4

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??

1
  • I've seen weird problems with system all the way up to the point where it comes down to using single or double quotes. Try using shell exec instead. ca3.php.net/manual/en/function.shell-exec.php Commented Oct 17, 2010 at 13:11

1 Answer 1

4

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

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

Sign up to request clarification or add additional context in comments.

1 Comment

that's the deal! Thank a lot!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.