小编cla*_*cke的帖子

bash:从`-x` 回显中转义单个行

在 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
Run Code Online (Sandbox Code Playgroud)

运行上述程序时,输出为:

+ echo the next-next line still echoes 'set +x,' is that 'avoidable?'
the next-next line still echoes set +x, is that …
Run Code Online (Sandbox Code Playgroud)

shell bash debugging

14
推荐指数
1
解决办法
5511
查看次数

标签 统计

bash ×1

debugging ×1

shell ×1