In my terminal window (using Max OS X) my shell is bash. However when I run a command in PHP via shell_exec or backtick operators I see that PHP is using the Bourne Shell (sh). Here's an example of what I'm seeing:
From within my terminal window:
$ echo $0
- bash
Also if I call php as follows:
$ php -r "echo shell_exec('echo $0');"
-bash
However, if I create a script called test.php with the following:
<?php echo shell_exec('echo $0'); ?>
And then run test php I get the following:
$ php test.php
sh
I'm wanting to use the bash shell when calling shell_exec - why is it choosing the Bourne shell and can I force it to use bash?
Thanks!
Dan
Reverse the quotes in your second command:
With the quotes as you had them in your question, the variable
$0
is expanded before the command is sent tophp
.If you want to force the use of Bash, you could do something like:
Assuming that:
one of the possible (but not optimal) solutions would be to change the default shell of the user account under which your web server is executed.
It probably reads the SHELL environment variable.Disregard that, putenv() didn't work.Try to just run the command you want with bash, like