Skip to main content
Wordingnand formatting.
Source Link

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

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

As each DoMyScript.py itselfinstance 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;pythontxt; python DoMyScript.py &; done 

However, this results in the below error:

-bash: syntax error near unexpected token `;'

-bash: syntax error near unexpected token `;' 

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 `;'

I have been using this command successfully, which changes a variable in a config file and 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 instance 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 `;' 
Source Link
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 `;'