Invoke Bash with a shell option set
According to the Invoking Bash section of the Bash manual,
All of the single-character options used with the set builtin (see The Set
Builtin) can be used as options when the shell is invoked
This means you can run a Bash script with the xtrace
option set by directly invoking bash
with the -x
option and the file name of the script as an argument, e.g.,
bash -x /path/to/script
Configure shell option for all shell scripts
When you say “global”, I presume you want it set the xtrace
option for all non-interactive invocations of Bash. To do this, set the BASH_ENV
environment variable to a suitable filename and then create that file with set -x
as its contents:
export BASH_ENV=~/.bash_env
echo set -x > ~/.bash_env
From the man page:
When bash is started non-interactively, to run a shell script, for example,
it looks for the variable BASH_ENV
in the environment, expands its value
if it appears there, and uses the expanded value as the name of a file to
read and execute.