dimanche 20 novembre 2016

If statement inside a for loop

Here i have a list (/test/list) contains 3 words: foo, bar, bla . I tried run this code :

#!/bin/bash
list=$(cat /test/list)
for i in $list ;do
if [ "$i" = "foo" ]; then
echo "yes $i"
else 
echo "no $i"
fi
done

But the output is:

no foo
no bar
no bla

How can i do for have:

yes foo
no bar
no bla

I have tried many things but nothing work. Thx for help.

Aucun commentaire:

Enregistrer un commentaire