Eytan Naim
Eytan Naim

Reputation: 379

Propagate bash tracing (set -x) to all child scripts

How do I propagate bash tracing (set -x) to all child scripts without modifying the main script code? Is there such a way? Maybe an hidden environment variable?

Let's assume I have:

main.sh

#!/bin/bash
echo "Main script"
./child.sh

child.sh

#!/bin/bash
echo "child script"

I want to call main.sh with some flag/environment variable/whatever that will cause child.sh to run with set -e without changing any code

Upvotes: 1

Views: 634

Answers (1)

Antonio Petricca
Antonio Petricca

Reputation: 11036

I accomplished this task by creating a file $HOME/.bash_env like:

set -x

Then I added

export BASH_ENV=$HOME/.bash_env

to .bash_rc.

So, each scripts will get bash tracing enabled.

Upvotes: 2

Related Questions