I've been calling more advanced shell commands from PHP recently using shell_exec
As my commands become more complicated, I keep experiencing errors with things not being escaped properly. I want to be able to call shell_exec('echo '.$variable) and no matter what I put in $variable it will just echo it. Some things $variable could include are $ ~ ' " \n \r \c `` ( ) { } ; \
What's the best way to escape a shell command before executing it?
Does escapeshellcmd or escapeshellarg not do what you want?
shell_exec('echo '. escapeshellarg($variable));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With