3

I am still dealing with a bug from another question which has gone unanswered because I can't get debugging information.

I have scripts running other scripts and I need to see how the tty is getting disconnected from the terminal.

Is there any way to 'set -x' globally? I can't set it in the problem script because it is dynamically generated, not by me, but I'd like to see what's wrong with it.

5

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.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.