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.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With