我一直在bash脚本中使用“set -x”来帮助我调试一些函数,它一直很适合我
-x After expanding each simple command, for command, case command,
select command, or arithmetic for command, display the expanded
value of PS4, followed by the command and its expanded arguments or
associated word list.
但是我希望能够在离开功能之前清除它
例如:
#/bin bash
function somefunction()
{
set -x
# some code I'm debugging
# clear the set -x
set ????
}
somefunction
答案 0 :(得分:5)
引用手册:
使用+而不是 - 导致这些标志被关闭。
所以你正在寻找set +x
。
答案 1 :(得分:2)
考虑像
这样的函数foo () {
set -x
# do something
set +x
}
问题是,如果{<1}}选项在 -x
被调用之前已经设置,那么它将被foo
关闭。
如果要恢复旧值,则必须使用foo
测试是否已启用旧值。
$-
答案 2 :(得分:0)
有关更多信息,请参阅基本指南。这清楚地给你答案:
http://www.tldp.org/LDP/Bash-Beginners-Guide/html/Bash-Beginners-Guide.html
set -x # activate debugging from here
w
set +x # stop debugging from here