if/then-Schleife mit „cat“

if/then-Schleife mit „cat“

teams.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

Ich erhalte immer wieder den Fehler:

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

Ich bin nicht sicher, was ich mit meinem Code falsch mache.

Antwort1

Um [ und ] herum fehlt das Leerzeichen. Es sollte so aussehen:

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

verwandte Informationen