加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 双引号内的感叹号会导致奇怪的解析错误

发布时间:2020-12-15 18:26:29 所属栏目:安全 来源:网络整理
导读:参见英文答案 Strange behavior of argv when passing string containing “!!!!”3个 为什么这个命令行有效: $output='Irrelevant'; if [[ $output =~ Something ]]; then echo "I found something in the output." ; fi 这个给我一个奇怪的解析错误? $ou
参见英文答案 > Strange behavior of argv when passing string containing “!!!!”3个
为什么这个命令行有效:
$output='Irrelevant'; if [[ $output =~ Something ]]; then echo "I found something in the output." ; fi

这个给我一个奇怪的解析错误?

$output='Irrelevant'; if [[ $output =~ Something ]]; then echo "I found something in the output!" ; fi
-bash: !": event not found

与第一个版本相比,唯一的变化是在引号内回显的句子以感叹号结束.为什么Bash在第二个版本中给我错误?

如果重要,这是bash –version的输出:

GNU bash,version 4.2.24(1)-release (x86_64-pc-linux-gnu)
您可以将字符串换成单引号而不是双引号.

感叹号调用bash manual中描述的非常有用的历史扩展函数.

History expansions are introduced by the appearance of the history expansion character,which is ! by default. Only and ' may be used to escape the history expansion character.

例如,要执行以mysql开头的最后一个命令,请输入:

!mysql

或者执行包含单词grep的最后一个命令,输入:

!?grep

bash手册还记录了history expansion operators的语法.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读