我希望这两个输出都等于foo [Required] bar,但是一旦设置为nullglob,[Required]就消失了。为什么?
我在运行MacOS。
谢谢!
$ bash --version
GNU bash, version 5.0.18(1)-release (x86_64-apple-darwin19.5.0)
$ shopt -u nullglob
$ read < <(echo "foo [Required] bar"); echo $REPLY;
foo [Required] bar
$ shopt -s nullglob
$ read < <(echo "foo [Required] bar"); echo $REPLY;
foo bar发布于 2020-11-12 16:46:48
因为您没有引用变量$REPLY,所以文件名扩展是在展开变量之后进行的。
[Required]是文件名通配符模式。它将匹配以下任何字符:R、e、q、u、i、r、d。
您可能没有这样的文件名。nullglob选项意味着不匹配任何内容的通配符应该替换为空字符串,而不是保留为未展开。
这个故事的寓意是:引用你的变量,除非你想让它们进行文件名扩展。
https://stackoverflow.com/questions/64800499
复制相似问题