I know that this may sound as "not as intended by designer" but I have real life situation where a bash script I am modifying needs to call another bash script that I am not allowed to modify.
That "unmodifiable bash script" starts with:
source `dirname $0`/setenv.sh
(that setenv.sh
also starts with SCR2PATH=source "$( cd "$(dirname "$0")" ; pwd -P )"
and is also unmodifiable)
Is there a trick in which I can fool the child script with a different $0
than that of the calling script?
$0
to have? Can you show us the script you can actually modify? What is thesource "$( cd "$(dirname "$0")" ; pwd -P )"
supposed to do? That will attempt to source a directory, you should be getting an error.execve
system call allows setting $0 to any arbitrary value you just need a way to exploit fhat from inside your script.