需要關於while命令的幫助。我想運行一個命令,如果有一個在playlist.txt
這裏,$站點名是我的bash:
cat playlist.txt | grep -e "$sitename" | sed -e "s/^.*\(http:.*"$sitename".*flv\).*$/\1/g" | sort | uniq > checklist.txt
cat checklist.txt
while [ " While can find $sitename in checklist.txt" ]; do
qa
done
這就是我曾嘗試已經
while [ -n "$echopl" ]; do
qa
done
while [ 'grep -q $string checklist.txt >/dev/null' ]; do
qa
done
while [ "grep -q "$string" checklist.txt" ]; do
qa2
done
while grep -q "$string" checklist.txt; do
qa
done
while grep -q '$string' checklist.txt; do
qa
done
if grep -q "$string" checklist.txt ; then
qa
fi
暫時我把很多,如果命令: (
ifmorelinks ifmorelinks ifmorelinks ifmorelinks ifmorelinks
奏效。謝謝! – 2011-12-18 12:17:10
來自man grep(1):_Portability註釋:與GNU grep不同,第7版Unix grep不符合POSIX,因爲它缺少-q和-s選項的行爲與GNU grep的-q選項相同。 USG風格的grep也缺少-q,但它的-s選項表現得像GNU grep。可移植shell腳本應避免-q和-s,並應將標準錯誤輸出重定向到/ dev/null ._ – 2011-12-18 16:18:49
此解決方案存在問題:如果$ string包含正則表達式元字符,它將被解釋!所以,如果你有,在你的字符串中說'a.com',它會匹配清單中的'fatcomparse.org'。你最好使用'fgrep'或者'grep -F'。另外,請考慮'-w'選項。 – fge 2011-12-18 16:33:20