2011-12-18 6 views
1

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

答えて

1
if grep "$string" checklist.txt >/dev/null 2>&1 ; then 
    qa 
fi 
+0

を。ありがとう! –

+0

man grep(1)から:_ポータビリティノート:GNU grepとは異なり、第7版Unix grepは-qがなく、-sオプションがGNU grepの-qオプションのように動作するため、POSIXに準拠していませんでした。 USGスタイルのgrepにも-qはありませんでしたが、-sオプションはGNU grepのように動作しました。移植可能なシェルスクリプトは、-qと-sの両方を避け、標準出力とエラー出力を/ dev/nullにリダイレクトする必要があります。 –

+1

この解決策には問題があります: '$ string'に正規表現メタ文字が含まれていると解釈されます!だから、文字列に 'a.com'と答えたら、あなたのチェックリストにある 'fatcomparse.org'にマッチします。代わりに 'fgrep'を使うか、' grep -F'を使うのがよいでしょう。また、 '-w'オプションを考慮してください。 – fge

2
while grep -q "$string" checklist.txt; do 
    qa 
done 

$stringは文字通り$stringなくstring変数の値を意味している場合、この使用:勤務

while grep -q '$string' checklist.txt; do 
    qa 
done 
+0

動作しません。すでに試してみました。 checklist.txtに "$ string"がなくてもqaが実行されます。 –

+0

ok、更新を参照 – unbeli

+0

同じことがループに入ります。 –

関連する問題