dmorlock
dmorlock

Reputation: 2021

Run bash script in PHP results in syntax error

I can use the following bash script to start severals terminals at once:

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

But if I try to run that bash script from a PHP script if fails with 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 fails, too:

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

Without '&' no errors occurs but I want to start all in background. Escaping the '&' results in an invalid argument error of urxvt.

Any ideas??

Upvotes: 4

Views: 1035

Answers (1)

Alberto Zaccagni
Alberto Zaccagni

Reputation: 31590

Remove the ;, the & is the termination of the command.

Type man bash in your shell and look at "Lists" under the "SHELL GRAMMAR" section.

Upvotes: 4

Related Questions