Let’s say I do set -x
in a script “a.sh”, and it invokes another script “b.sh”.
Is it possible to let “b.sh” inherit the -x
option from “a.sh”?
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.
Just as important are the things that a subshell does not inherit from its parent: Shell variables, except environment variables and those defined in the environment file (usually .
set -e The set -e option instructs bash to immediately exit if any command [1] has a non-zero exit status. You wouldn't want to set this for your command-line shell, but in a script it's massively helpful.
To make a variable available in a subshell (or any other subprogram of the shell), we have to “export” the variable with the export command.
export SHELLOPTS
for example:
echo date > b chmod +x b
without the export, we only see the commands in ./a
when it calls ./b
:
$ echo ./b > a $ bash -xv a ./a + ./b Sun Dec 29 21:34:14 EST 2013
but if we export SHELLOPTS, we see the commands in ./a
and ./b
$ echo "export SHELLOPTS; ./b" > a $ bash -xv a ./a + ./b date ++ date Sun Dec 29 21:34:36 EST 2013
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