if/then 使用 `cat` 循環

if/then 使用 `cat` 循環

團隊.txt:

Bills
Jets
Dolphin
Patriots

for team in `cat teams.txt`
do
    if ["$team" == "Bills"]
    then
        echo "$team hired Rex Ryan as coach"
    fi
    echo "$team Nation"
done

我不斷收到錯誤:

teams.sh: line 5: [Bills: command not found

我不確定我的程式碼做錯了什麼。

答案1

您缺少 [ 和 ] 周圍的空格。它應該看起來像這樣:

for team in `cat teams.txt`
do
    if [ "$team" == "Bills" ]
    then
        echo "$team hired Rex Ryan as coach"
    fi
    echo "$team Nation"
done

相關內容