grep --exclude-dir アクション: バグまたは機能?

grep --exclude-dir アクション: バグまたは機能?

grep -r --exclude-dir私は行動に不安な変化があることを発見しました。次のテストを検討してください。

mkdir -p ./d1/d2
echo 'randomtext' > ./d1/d2/testfile

grep -nr --exclude-dir ./d1/d2 'randomtext'

予想される動作は、grepが渡す必要がある「testfile」を表示しないことです--exclude-dir。これはgrep v2.10と2.11で動作します。ただし、バージョン2.12+の場合、出力は次のようになります。

./d1/d2/testfile:1:randomtext

また、動作は一貫していません。

grep -nr --exclude-dir d1 'randomtext'
# or 
grep -nr --exclude-dir d2 'randomtext'

期待どおりに出力なしでうまく機能します。

私はこれがバグだと思います。私の理論を確認できますか?ありがとうございます。

ベストアンサー1

v2.11とv2.12の間のgrep変更ログには、次の変更のみが記載されています--exclude-dir

grep: fix segfault with -r --exclude-dir and no file operand

私は動作の変化がこの修正の副作用であると思います(まさにあなたの場合です)。つまり、バグが発生しましたが、ご覧のとおり、grepv2.12以前でもこの場合セグフォルトが可能でした。したがって、v2.11が安定しているとは思わないでください。

このバグを報告することをお勧めします。

注:この分割エラーはv2.11の修正によって発生します。ドキュメントNEWSにはv2.11について次のように記載されています。

The --include, --exclude, and --exclude-dir options now handle
command-line arguments more consistently.  --include and --exclude
apply only to non-directories and --exclude-dir applies only to
directories.  "-" (standard input) is never excluded, since it is
not a file name.
[bug introduced in grep-2.5]

v2.12の場合:

grep no longer segfaults with -r --exclude-dir and no file operand.
I.e., ":|grep -r --exclude-dir=D PAT" would segfault.
[bug introduced in grep-2.11]

おすすめ記事