Skip to main content
1 of 2
ljs.dev
  • 2.1k
  • 4
  • 20
  • 32

Use & (ampersand) in single line bash loop

I have been using this command successfully, which changes a variable in a config file then executes a Python script within a loop:

for((i=114;i<=255;i+=1)); do echo $i > numbers.txt;python DoMyScript.py; done 

As each DoMyScript.py itself takes about 30 seconds to run before terminating, I'd like to relegate them to the background while the next one can be spawned.

I have tried what I am familiar with, by adding in an ampersand as below:

for((i=114;i<=255;i+=1)); do echo $i > numbers.txt;python DoMyScript.py &; done 

However, this results in the below error:

-bash: syntax error near unexpected token `;'

ljs.dev
  • 2.1k
  • 4
  • 20
  • 32