Bash install + x without printing

Does anyone know if we can say set +x in bash without printing it:

 set -x command set +x 

traces

 + command + set +x 

but he should just type

 + command 

Bash - version 4.1.10 (4). This has been listening to me for some time - the output is cluttered with useless set +x lines, which makes the tracer not as useful as it could be.

+47
bash shell
Nov 02
source share
3 answers

I had the same problem and I was able to find a solution that does not use a subshell:

 set -x command { set +x; } 2>/dev/null 
+73
Oct 07 '13 at 13:21
source share

You can use a subshell. After exiting the subshell, the x value will be lost:

 ( set -x ; command ) 
+28
Nov 02
source share

I cracked the solution for this recently when I pissed it off:

 shopt -s expand_aliases _xtrace() { case $1 in on) set -x ;; off) set +x ;; esac } alias xtrace='{ _xtrace $(cat); } 2>/dev/null <<<' 

This allows you to enable and disable xtrace, as in the following, where I register how arguments are assigned to variables:

 xtrace on ARG1=$1 ARG2=$2 xtrace off 

And you get an output that looks like this:

 $ ./script.sh one two + ARG1=one + ARG2=two 
+6
Jul 01 '14 at 18:32
source share



All Articles