看起来 set -v
在子 shell 中不起作用?为什么?
(set -x
确实在子 shell 中工作,但输出有点忙)。
$ cat foo.sh
set -v
date
set +v > /dev/null 2>&1
$ bash foo.sh
date
Fri Mar 3 14:52:34 PST 2017
set +v > /dev/null 2>&1
$ cat foo_subshell.sh
(
set -v
date
)
$ bash foo_subshell.sh
Fri Mar 3 14:52:42 PST 2017
最佳答案
文档说:
-v
Print shell input lines as they are read.
当您在括号中编写子 shell 时,将读取整个子 shell,然后执行。因此 set -v
命令直到所有命令都被读取后才执行,所以它来不及打印它们了。
关于bash - 为什么 "set -v"似乎不能在 bash 的子 shell 中工作?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42589827/