特定のテキストのすべてのヘッダー ファイルを検索し、各ヘッダー ファイルが他のファイルに含まれる回数を調べる UNIX シェル スクリプトを作成しようとしています。
私の問題は 2 番目の部分にあります。他のファイルのインクルードを検索するコマンドはコマンド ラインから機能しますが、シェル スクリプトからは何も出力しません。
array=( $(grep 'regexToSearch' -rl --include="*.h" pathToFiles) )
for item in "${array[@]}"
do
filename=$(echo ${item} | grep -o '[^/]*.h')
incstring="#include[ ]*\"$filename\""
echo $incstring
echo "--------------------"
filelist=$(grep '$incstring' -rl --include=*.{h,cpp} pathToFiles)
echo $filelist
echo "--------------------"
done
出力は次のとおりです。
#include[ ]*"header1.h"
--------------------
// Second grep output for first file should be here
--------------------
#include[ ]*"header2.h"
--------------------
// Second grep output for second file should be here
--------------------
#include[ ]*"header3.h"
--------------------
// Second grep output for third file should be here
--------------------