BASH 手册页local说
local [option] [name[=value] ... | - ]
[…] If name is ‘-’, the set of shell options is made local to the
function in which local is invoked: shell options changed using the
set builtin inside the function are restored to their original
values when the function returns.
Run Code Online (Sandbox Code Playgroud)
因此,根据这些信息,使用local -,我应该能够set -x在函数内部使用来启用跟踪输出。当函数结束时,跟踪输出将被禁用。
#!/bin/bash
foo() {
local -
set -x
... # this code is shown in trace output
}
# trace output is …Run Code Online (Sandbox Code Playgroud) bash ×1