3

Suppose I've got a bash script foo.bash, which uses exec to run another bash script:

exec bar.bash

Now am debugging both foo.bash and bar.bash. I am running foo.bash with bash -x but it does not run bar.bash in debug mode. What should I do to run bar.bash in debug mode too ?

2 Answers 2

3

You can also export SHELLOPTS from foo.bash as well to export the shell options.

export SHELLOPTS
Sign up to request clarification or add additional context in comments.

2 Comments

Can I do it without modifying foo.bash ?
You can set in -x from the calling shell: $ set -x; export SHELLOPTS; ./foo.bash - this wouldn't require changes to foo.bash. You can also run this from a subshell so that debug output is not printed for everything else: $ (set -x; export SHELLOPTS; ./foo.bash).
1

Add -x to bar.bash's shebang line:

#!/bin/bash -x

If you don't want to modify bar.bash, change the exec line to:

exec bash -x bar.bash

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.