【问题标题】:echo ![alt causes event not found [duplicate]echo ![alt 导致事件未找到 [重复]
【发布时间】:2017-01-09 18:13:33
【问题描述】:

简单运行

echo "This is a **test** see ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png)"

你得到:

bash: ![alt: event not found

为什么?预计This is a **test** see ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png)

【问题讨论】:

  • 您可以像示例中一样保留双引号,但通过删除 ! 变量的特殊处理来防止历史扩展。在!之前添加\

标签: bash echo


【解决方案1】:

使用单引号

echo 'This is a **test** see ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png)'

单引号将您通过的测试逐字记录。虽然双引号字符串由 bash 解释,例如 $VAR 表示变量,$(..) 将执行命令并插入标准输出,[...] 被视为布尔评估器,! 被视为 NOT,等等.来自 bash 手册:

用双引号括起来的字符会保留引号内所有字符的字面值,除了 $,, \, and, when history expansion is enabled, !. The characters $ and 在双引号内保留其特殊含义。反斜杠仅在后跟以下字符之一时才保留其特殊含义:$、`、"、\ 或除非出现在双引号中的 ! 使用反斜杠转义。不会删除 ! 前面的反斜杠。

【讨论】:

  • echo中的单引号和双引号有什么区别?
  • 我扩展了答案来回答你的问题
【解决方案2】:

! 被解释为 NOT(逻辑非)运算符,因此 [alt 被视为 命令。在这里使用单引号可能是最好的选择:

 echo 'This is a **test** see ![alt text](https://github.com/adam-p/markdown-here/raw/master/src/common/images/icon48.png)'

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-11-27
    • 1970-01-01
    • 2019-12-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-14
    • 1970-01-01
    相关资源
    最近更新 更多