Running bash script in PHP leads to syntax error

I can use the following bash script to run separate output terminals at the same time:

for i in 0 1 2 3; do urxvt -name Terminal$i&; done 

But if I try to run this bash script with a PHP script, if the failure occurred with an error:

 sh: -c: line 0: syntax error near unexpected token `;' sh: -c: line 0: `for i in 0 1 2 3; do urxvt -name Terminal$i&; done' 

PHP script:

 <?php system('for i in 0 1 2 3; do urxvt -name Terminal$i&; done'); ?> 

This also fails:

 <?php exec('for i in 0 1 2 3; do urxvt -name Terminal$i&; done'); ?> 

There are no errors without '&', but I want to start everything in the background. Leaving '&' results in an invalid urxvt argument error.

Any ideas?

+4
source share
1 answer

Remove ; , & is the completion of the command.

Enter man bash into your shell and see the "Lists" section of the "SHELL GRAMMAR".

+4
source

All Articles