2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

CentOS 6.7にアップデートしたらgrepの動きが壊れた

Last updated at Posted at 2016-06-03

RHEL 6.7/CentOS 6.7で grep のバージョンが 2010年4月の 2.6.3 から 2014年6月の 2.20 まで一気に上がってしまった影響で、grep の一部のオプションの動作が変更されております。

秘伝のタレ的な .bashrc もしくは .bash_profile などで、以下のような alias を仕込んでいたとします。

.bashrc
alias grep='grep -nr -E --color=auto'

そうすると、例えば

cat anaconda-ks.cfg | grep logvol

とかすると、 alias-r オプションのせいで、カレントディレクトリ以下のディレクトリやファイルに対し再帰的に grep が実行され作業者は死ぬ。

回避方法1

cat anaconda-ks.cfg | \grep logvol

grep に設定された alias を無視するバックスラッシュをつける書き方。素の grep をお楽しみいただけます。

回避方法2

alias をやめて、環境変数 GREP_OPTIONS に設定を移設する。

bash_profile
export GREP_OPTIONS="-nr -E --color=auto"
cat anaconda-ks.cfg | grep logvol

この場合は、バックスラッシュをつけても環境変数のオプションを使うので注意。

環境変数 GREP_OPTIONS を一時的に空にして素の grep を実行したい場合は、こう書く。

# export GREP_OPTIONS="-nr -E --color=auto" の実行後のシェルだとして
GREP_OPTIONS= grep part Maildir/

実行結果( -r オプションが効かないので、エラーが出る)

grep: Maildir/: ディレクトリです

参考URL

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?