Home > Software design >  i can not get bash For loops to work, anything after do becomes an unexpected token
i can not get bash For loops to work, anything after do becomes an unexpected token

Time:10-22

for some reason this:

#!/bin/bash
for ln in {1 2 3}; do
done
exit 0

produces the following error:

./Untitled-1.sh: line 3: syntax error near unexpected token done' ./Untitled-1.sh: line 3: done'

can anyone tell me what i am doing wrong here?

CodePudding user response:

You need to do something in the loop. E.g.

echo "$ln"

That will also show you that the brace expansion doesn't use spaces to separate elements.

The correct syntax would be

for ln in 1 2 3 ; do
# or
for ln in {1,2,3} ; do
  • Related