指定のファイルが検索できない。検索開始のフォルダにより動作しない。
Mac上で以下のバッチコマンドを作成し、特定のファイルの文字を検索する。
#find . -name "$2" -type f -print | xargs grep $1 # check the problem echo $2 find . -name "$2" -type f -print
正常動作のフォルダ
-rw-r--r-- 1 xxxxx staff 46 Oct 27 16:21 CHANGELOG.md -rw-r--r-- 1 xxxxx staff 475 Oct 27 16:09 README.md drwxr-xr-x 4 xxxxx staff 136 Oct 25 22:57 _build/ drwxr-xr-x 3 xxxxx staff 102 Oct 25 22:28 config/ drwxr-xr-x 10 xxxxx staff 340 Oct 25 22:53 deps/ drwxr-xr-x 19 xxxxx staff 646 Oct 27 16:21 doc/ drwxr-xr-x 4 xxxxx staff 136 Oct 25 22:28 lib/ -rw-r--r-- 1 xxxxx staff 943 Oct 27 16:19 mix.exs -rw-r--r-- 1 xxxxx staff 1480 Oct 25 22:53 mix.lock drwxr-xr-x 4 xxxxx staff 136 Oct 25 23:07 test/ # 結果: *.ex ./deps/earmark/lib/earmark/block.ex ./deps/earmark/lib/earmark/cli.ex ./deps/earmark/lib/earmark/context.ex - - # echo $2 => *.ex
動作しないフォルダ
-rw-r--r-- 1 xxxxx staff 1640 Oct 25 22:32 graphvix.ex drwxr-xr-x 10 xxxxx staff 340 Oct 25 22:34 graphvix/ #結果 graphvix.ex ./graphvix.ex # echo $2 => graphvix.ex ---> *.exとなっていない
検索するフォルダにより渡す変数が変わる
正常ケースは「*.ex」が渡っているが、不良の場合、「graphvix.ex」と変わってしまう。従って、サブフォルダの検索がされない。
試したこと
バッチファイルでなく、そのままfindコマンドを使うと問題がない
$ find . -name "*.ex" -type f -print
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/11/01 01:08
2018/11/01 01:18