Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Loop background job

Tags:

bash

I try to run a background job in a for loop in bash:

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

I get error:

bash: syntax error near unexpected token `;' 

In zsh the command line works.

like image 998
bougui Avatar asked Sep 18 '12 08:09

bougui


1 Answers

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 
like image 174
gammay Avatar answered Oct 10 '22 06:10

gammay