Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not print strict-mode commands when set -x is on #4

Open
olivergondza opened this issue Oct 26, 2021 · 0 comments
Open

Do not print strict-mode commands when set -x is on #4

olivergondza opened this issue Oct 26, 2021 · 0 comments

Comments

@olivergondza
Copy link
Owner

Consider doing trap '{ s=$?; set +x; } 2>/dev/null; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR to prevent all commands to be printed in case the shell failed while set -x is on. Additionally, other traps are printed, which might be desirable, and the suggested snippet prevents that.

++ s=1
++ echo './script.sh: Error on line 127: COMMAND_LINE_HERE'
./script.sh: Error on line 127: COMMAND_LINE_HERE
++ exit 1
+ rm -rf /tmp/temp-dir.zM0

With this change on, the script fails with:

./script.sh: Error on line 127: COMMAND_LINE_HERE
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant