我有兩個檔案名為
file1 = "my_random_forest_2021-08-11-094538.csv.zip"/span>
file2 = "my_random_forest_2021-08-11-094538.csv.zip"。
if [$file1 ==$file2]; then
echo " matched"
執行該腳本時,它說:
test.sh: line 5: [my_random_forest_2021-08-11-094538. csv.zip: command not found。
如何比較帶有上述格式的檔案名?
uj5u.com熱心網友回復:
正確的語法應該是這樣的
file1="my_random_forest_2021-08-11-094538.csv.zip"/span>
file2="my_random_forest_2021-08-11-094538.csv.zip"
if [ $file1 = $file2 ]
然后
echo " matched"
Fi
在宣告變數的時候沒有空格。
變數和方括號之間應該有空白。
;在if后面不是必須的。如果你想在一行中加入if和然后,你可以加入;
匹配將使用=而不是==.
if應該以fi結束,以結束陳述句。
uj5u.com熱心網友回復:
if [ "$file1" = "$file2" ] 。then
echo " matched";
fi; fi
你在方括號和變數名之間缺少一個空格。沒有空格,shell就會把"[my_random_forest_2021-08-11-094538.csv.zip "解釋為一個命令(這個命令并不存在)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/318133.html
標籤:
