Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/linux/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Linux 清洁'-x选项';在脚本中_Linux_Bash - Fatal编程技术网

Linux 清洁'-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

我一直在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.
但是,我希望在离开函数之前能够清除它

例如:

引用手册:

使用+而不是-会导致关闭这些标志

因此,您需要的是
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
这样的东西可以切换值的世界。:)