gpt4 book ai didi

linux - 为什么 shell 解释单引号内的字符?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:18:46 25 4
gpt4 key购买 nike

我正在使用 bash shell

$cat test
a --b

$grep '--b' test
grep: option `--b' is ambiguous
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.

$grep "--b" test
grep: option `--b' is ambiguous
Usage: grep [OPTION]... PATTERN [FILE]...
Try `grep --help' for more information.

$grep '\-\-b' test
a --b

经典的 shell 脚本书籍第 7 章“输入和输出、文件和命令评估”中的 7.7 节引用说

"Single quotes force the shell to treat everything between the pair of quotes literally".

那为什么上面的单引号不起作用呢?

最佳答案

shell 按字面意思对待它们。但是 shell 不负责应用程序 如何对待它们。应用程序决定如何处理作为参数传递的 --b

关于linux - 为什么 shell 解释单引号内的字符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7945631/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com