Is it possible to change the $0 argument of a shell script (bash script) explicitly while running the script? Consider the following script: readonly SCRIPT_HELP=$(cat <<EOF Usage: $(basename $0) [-h]EOF ) echo ${SCRIPT_HELP}Is it possible to pass something else as an argument 0 to this bash script so the evaluation $(basename... would be executed with some user supplied code (potentially harmful)? And generally, if it's possible to exploit the fact that the argument 0 is not sanitized properly in a particular shell script? 
Bash script arg0 vulnerability?
shell script;scripting;security
It is trivially possible to decide what $0 should be. Simply create a link:$ cat foo.sh#! /bin/bashreadonly SCRIPT_HELP=$(cat <<EOFUsage: $(basename $0) [-h]EOF)echo ${SCRIPT_HELP}$ ./foo.shUsage: foo.sh [-h]EOF$ ln -s foo.sh bar.sh$ ./bar.shUsage: bar.sh [-h]EOFIn this particular case, no, I don't imagine it will be possible to use that to any great advantage. $0 and SCRIPT_HELP are quoted when used (within nested command substitutions and heredocs, but quoted nonetheless), and they're not being evaled.$ ln -s ./foo.sh '; echo rm -rf ~; echo'$ ./\\;\ echo\ rm\ -rf\ \~\;\ echo\Usage: ; echo rm -rf ~; echo [-h]EOF