Linux 清洁'-x选项';在脚本中
我一直在bash脚本中使用“set-x”来帮助我调试一些函数,它对我来说工作得非常好Linux 清洁'-x选项';在脚本中,linux,bash,Linux,Bash,我一直在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 co
-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.
但是,我希望在离开函数之前能够清除它
例如:
引用手册:
使用+而不是-会导致关闭这些标志
因此,您需要的是set+x
。引用手册:
使用+而不是-会导致关闭这些标志
因此,您需要的是
set+x
。有关更多信息,请参阅基本指南。这清楚地给了你答案:
有关更多信息,请参阅基本指南。这清楚地给了你答案:
考虑一个函数,如
foo () {
set -x
# do something
set +x
}
问题是,如果在调用foo
之前已经设置了-x
选项,它将被foo
关闭
如果要恢复旧值,必须使用$-
测试是否已启用该值
foo () {
[[ $- != *x* ]]; x_set=$? # 1 if already set, 0 otherwise
set -x
# do something
(( x_set )) || set +x # Turn off -x if it was off before
}
考虑一个函数,如
foo () {
set -x
# do something
set +x
}
问题是,如果在调用foo
之前已经设置了-x
选项,它将被foo
关闭
如果要恢复旧值,必须使用$-
测试是否已启用该值
foo () {
[[ $- != *x* ]]; x_set=$? # 1 if already set, 0 otherwise
set -x
# do something
(( x_set )) || set +x # Turn off -x if it was off before
}
与我所要求的相比,能够恢复以前的状态是一个很大的改进。谢谢我渴望一个像
set±x
这样的东西可以切换值的世界。:)与我所要求的相比,能够恢复以前的状态是一个很大的改进。谢谢我渴望一个像set±x
这样的东西可以切换值的世界。:)