在bash中,使用该-x
选项运行时,是否可以排除单个命令的回显?
我正在尝试使输出尽可能整洁,因此我正在使用的子外壳中运行脚本的某些部分set +x
。但是,该行set +x
本身仍然被回显,并且没有向输出添加任何有价值的信息。
我记得在糟糕的过去.bat
,与一起运行时echo on
,可以通过以开头来免除单独的行@
。bash有任何等效功能吗?
#!/bin/bash -x
function i_know_what_this_does() {
(
set +x
echo do stuff
)
}
echo the next-next line still echoes 'set +x', is that avoidable?
i_know_what_this_does
echo and we are back and echoing is back on
运行以上命令时,输出为:
+ echo the next-next line still echoes 'set +x,' is that 'avoidable?'
the next-next line still echoes set +x, is that avoidable?
+ i_know_what_this_does
+ set +x
do stuff
+ echo and we are back and echoing is back on
and we are back and echoing is back on