bash - 为什么 "set -v"似乎不能在 bash 的子 shell 中工作?

标签 bash shell debugging

看起来 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/

相关文章:

node.js - 如何向Docker容器发送命令?

bash - 在 bash 中解析输出

shell - 从文本文件中逐行读取并在 shell 脚本中按照我想要的方式打印

linux - 如何将 "which"与正则表达式或其他方式一起使用以在 $PATH 中查找命令

macos - 是否可以在 Mac OS 上调试 x64 程序集?

linux - sed - 在文件的最后一行之前管道化一个字符串

bash - 如何在bash命令行上输出文件列表

c - 简单linux shell中的环境变量

c - 为什么 GDB 不显示导致段错误的函数地址

javascript - BestBuy 网站上 Internet Explorer 8 中非常奇怪的极端情况行为