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

相关内容