我想檢查從程序輸出的字符串,如果字符串匹配某個內容,while循環將停止程序。與此同時,我需要算多少次的程序運行:shell腳本:使用while循環來檢查字符串內容使用[]
x = "Lookup success" # this is supposed to be the output from the program
INTERVAL=0 # count the number of runs
while ["$x" != "Lookup failed"] # only break out the while loop when "Lookup failed" happened in the program
do
echo "not failed" # do something
$x = "Lookup failed" # just for testing the break-out
INTERVAL=(($INTERVAL + 10)); # the interval increments by 10
done
echo $x
echo $INTERVAL
但這shell腳本不工作,與此錯誤:
./test.sh: line 9: x: command not found
./test.sh: line 12: [[: command not found
有人能幫助我嗎?我感謝您的幫助。
如果它幫助你,請接受或提出答案。 – Anubhab