我知道輸出未被識別為整數,但我不明白為什么?該檔案有超過 5 行。
$ if [ "$(wc -l test.txt)" -gt "$5" ]; then
echo changes found;
else
echo No changes found;
fi
bash: [: 6 test.xml: integer expression expected
No changes found
uj5u.com熱心網友回復:
我剛試過這個:
wc -l test.txt
結果如下:
5 test.txt
所以結果包含一個數字,后跟檔案名。
你可以像這樣解決它:
wc -l test.txt | awk '{print $1}'
這僅給出數字。
因此,您可以將代碼更改為:
$ if [ "$(wc -l test.txt | awk '{print $1}')" -gt "$5" ]; then
...現在正確:
$ if [ $(wc -l test.txt | awk '{print $1}') -gt 5 ]; then
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/414669.html
標籤:
上一篇:從slug中省略檔案擴展名
