Bashスクリプトのカラー出力

Bashスクリプトのカラー出力

私はgrepこれをbashスクリプトで実行しています。コマンドを直接実行すると、grepファイル名と検索文字列がカラーで出力されます。

grep -i username /tmp/sess_*

このコマンドをbashスクリプトに入れると機能しますが、色は失われます。カラー出力を保存する方法は?

ベストアンサー1

--color=alwaysgrepに追加できます。

私のローカルマンページの関連セクション:

  --color[=WHEN], --colour[=WHEN]
          Surround  the  matched  (non-empty)  strings,  matching   lines,
          context  lines,  file  names,  line  numbers,  byte offsets, and
          separators (for fields and groups of context lines) with  escape
          sequences  to display them in color on the terminal.  The colors
          are  defined  by  the  environment  variable  GREP_COLORS.   The
          deprecated  environment  variable GREP_COLOR is still supported,
          but its setting does not have priority.  WHEN is never,  always,
          or auto.

〜のようにこの問題したがって、ファイルgrepにマップするエイリアスがある可能性があり、スクリプトはそのエイリアスを読み取らないため、スクリプトに適用されない可能性があります。grep --color=auto.bashrc

おすすめ記事