[英]execute shell command with variable
為了從txt文件中的一些變量執行“查找”,我這樣做了,但它不起作用。 執行語句有問題嗎?
#/bin/bash
while read line;
do
echo tmp_name: $line
for ST in 'service.getFile("'$line;
do
find ./compact/ -type f -exec grep -l $ST {} \;
done
done < tmpNameList.txt
嘗試在您的find
命令中引用$ST
。
更重要的是:
./
; 您似乎沒有任何特殊的正則表達式字符( (
必須在grep
的經典正則表達式模式中加引號,並且我假設您的確是文字點),因此請改用fgrep
(或grep -F
)。
find compact/ -type f -exec fgrep -l "$ST" {} \\;
grep
可以從文件讀取多種模式( -f
選項):
find ./compact/ -type f -exec grep -f patterns.txt {} +
其中patterns.txt
(在每行前添加'service.getFile('
))為:
sed 's/^/service.getFile(/' tmpNameList.txt >patterns.txt
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.