vendredi 9 septembre 2016

Bash syntax for a for loop with if elif statements

Pretty basic question for a rusty bash'er.

I want to for loop over a variable and submit it to a set of if elif conditions.

Here's wat I'm trying:

for i in {1..10}
do
    if [ $i >= 10 && $i < 100 ]
        echo $i
    elif [ $i >= 100 && $i < 1000 ]
      echo $i
    else
      echo $i
    fi
done

But that doesn't work. What's missing/wrong?

Aucun commentaire:

Enregistrer un commentaire