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

おすすめ記事