问题
Need help with the while command. I want to run a command if there's a $sitename in playlist.txt
Here's my 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
that's what i have tried already
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
Temporarily I put many if commands :(
ifmorelinks ifmorelinks ifmorelinks ifmorelinks ifmorelinks
回答1:
if grep "$string" checklist.txt >/dev/null 2>&1 ; then
qa
fi
回答2:
while grep -q "$string" checklist.txt; do
qa
done
If $string
means literally $string
and not the value of string
variable, use this:
while grep -q '$string' checklist.txt; do
qa
done
来源:https://stackoverflow.com/questions/8551382/while-command-in-bash-if-theres-a-string-in-file-txt-do