我必須為作業撰寫一個 C Shell 腳本,我不知道為什么我的 if 陳述句顯然格式錯誤。我有這樣的事情:
#!/bin/csh -f
foreach line("`cat file.txt`")
set curr_line = `echo $line | awk '{print substr($0, 1, 20)}'`
if ($curr_line == "string of text...") then
echo "Success!"
endif
end
uj5u.com熱心網友回復:
想通了,我只需要在字串變數周圍加上引號:
if ("$curr_line" == "string of text...") then
echo "Success!"
endif
uj5u.com熱心網友回復:
在另一篇文章中提出了同樣的問題: 如果:運算式語法 - 在 C Shell 腳本中
您需要將命令包裝在 ' 中以在條件中使用結果。
所以這就是它應該的樣子:
if (`$curr_line == "string of text..."`) then
echo "Success!"
endif
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/327240.html
下一篇:如何傳遞引數并以所需格式輸出
