I am trying to call a shell script loop using the shell_exec()
php function but with no avail.
I can do shell_exec("ls")
with no problem.
I can ssh to the server and do for f in
ls; do echo $f ; done
with no problem.
But when I combine the two,
shell_exec("for f in `ls` ; do echo $f ; done")
I get nothing as output (nor NULL as error, I checked).
What am I missing here?
P.S: The for loop I am using here is not one I intend to use, it's just to make it clearer.
Your mistakes:
echo
$
sign should be escaped as soon as you're using double quotes (or double quotes may be replaced with single quotes instead)Pro tip: always develop with
error_reporting
levelE_ALL
(or higher) anddisplay_errors 1