Richi RM
Richi RM

Reputation: 1197

PHP system() or shell_exec(): execute another shell

I'm using system() and shell_exec() but it seems that this funcions use /bin/sh always. I want to use another shell when I call this functions: bash or zsh. Is it possible?

Upvotes: 0

Views: 412

Answers (2)

user1934428
user1934428

Reputation: 22217

What's the point? If you use system to start another shell script, that shell script itself can decide (via its #! line) which shell it is supposed to be processed by. Aside from this, you can always explicitly call the shell. For instance, if you want to take advantage of globbing operators specific to zsh or specific zsh builtins, you can do a

# Produce list of files including hidden files. Use
# the zsh-builtin command instead of /usr/bin/echo :
system('zsh -c "echo *(DN)"')

Upvotes: 0

Richi RM
Richi RM

Reputation: 1197

One solution can be:

<?php
   \system('bash -c "here your command"');

or

<?php
   \system('zsh -c "here your command"');

Upvotes: 0

Related Questions