Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash set +x without it being printed

Tags:

bash

shell

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.

like image 608
Andreas Spindler Avatar asked Nov 02 '12 12:11

Andreas Spindler


People also ask

What does [- Z $1 mean in bash?

$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.

What does bash set +X do?

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.

How do I turn off set X?

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.


2 Answers

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 
like image 165
McJoey Avatar answered Sep 21 '22 06:09

McJoey


You can use a subshell. Upon exiting the subshell, the setting to x will be lost:

( set -x ; command ) 
like image 26
choroba Avatar answered Sep 20 '22 06:09

choroba