Daniel YC Lin
Daniel YC Lin

Reputation: 16012

How to restore previous 'set -x' option in bash

I'm trying to debug my scripts. For example a.sh call b.sh.

#a.sh
echo "in a.sh"
source b.sh

#b.sh
echo "in b.sh"

If I'm sure b.sh is OK and just want to debug a.sh, I run as

bash -x a.sh

How to disable the display '-x' setting in b.sh, maybe modify b.sh as

#b.sh
x_option=$(get -x) # if there is such function
set +x
echo "in b.sh"
[ $x_optoin = 1 ] && set -x

Upvotes: 3

Views: 756

Answers (1)

Etan Reisner
Etan Reisner

Reputation: 80931

From the bash reference manual:

The current set of options may be found in $-.

Which means you can look in that value for the current state of -x.

Upvotes: 4

Related Questions