Loop background job

Solution 1:

Remove the ; after sleep

for i in $(seq 3); do echo $i ; sleep 2 & done

BTW, such loops are better written on separate lines with proper indentation (if you are writing this in a shell script file).

for i in $(seq 3)
do
   echo $i
   sleep 2 &
done

Solution 2:

You can put the background command in ( )

for i in $(seq 3); do echo $i ; (sleep 2 &) ; done