Does anyone know if we can say set +x
in bash without it being printed:
set -x command set +x
traces
+ command + set +x
but it should just print
+ command
Bash is Version 4.1.10(4). This is bugging me for some time now - output is cluttered with useless set +x
lines, making the trace facility not as useful as it could be.
$1 means an input argument and -z means non-defined or empty. You're testing whether an input argument to the script was defined when running the script. Follow this answer to receive notifications.
Bash provides the set command in order to enable or disable different features. The set -x command is used to debug bash script where every executed statement is printed to the shell for debugging or troubleshooting purposes.
If set -LETTER turns on an option, set +LETTER turns it off. Thus, set +x turns off traces. The last trace, for the set +x command itself, is not completely avoidable. You can suppress it with { set +x; } 2>/dev/null , but in some shells there's still a trace for the redirection itself.
I had the same problem, and I was able to find a solution that doesn't use a subshell:
set -x command { set +x; } 2>/dev/null
You can use a subshell. Upon exiting the subshell, the setting to x
will be lost:
( set -x ; command )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With