mercredi 24 février 2016

Using an IF ELSE statement inside a FOR loop in UNIX

I'm trying to use an IF/ELSE statement inside a FOR loops to generate two output files: count1 with numbers 1-5; count2 with numbers 6-10

I am trying

for i in {1..10}
do
        if [ $i -le 5 ]
        then
                echo $i > count1.out
        else
                echo $i > count2.out
        fi
done

but count1 only has "5" in it and count2 shows "10"

How can I fix this?

Aucun commentaire:

Enregistrer un commentaire