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

这是GNU Bash中的错误吗?

发布时间:2020-12-15 21:03:10 所属栏目:安全 来源:网络整理
导读:我在尝试支持字符串安全性的脚本时发现了这一点: $echo '!!'!!$echo "$(echo '!!')"echo "$(echo 'echo '!!'')" #~ the console echoes the line with expanded history hereecho !! #~ the result 在我看来,最内层的引用,单引号,不应该扩展任何东西,变量,
我在尝试支持字符串安全性的脚本时发现了这一点:

$echo '!!'
!!
$echo "$(echo '!!')"
echo "$(echo 'echo '!!'')"        #<~ the console echoes the line with expanded history here
echo !!                           #<~ the result

在我看来,最内层的引用,单引号,不应该扩展任何东西,变量,子shell或其他,但在这种情况下,它扩展了!!到最后一行输入.似乎不应该这样做.

我问你:这是Bash中的一个错误,如果可以使用引用的子shell扩展输出感叹号?

(在Linux中使用Bash 4.1.007)

编辑:

如果以上不是错误,那么为什么这样做会如预期的那样?

$foo='some value'
$echo "$(echo 'neither $foo nor `this subshell` should expand here')"
neither $foo nor `this subshell` should expand here

解决方法

我同意.

$echo "$(echo '!!')"
echo "$(echo 'echo $(echo '!!')')"
echo $(echo !!)

应该做同样的事情

$echo $(echo '!!')
!!

我看不出如何解释基于history expansion documentation的差异.

历史扩展文档与shell expansions documentation的其余部分完全分开也很奇怪.

zsh回声!!两者,至少我的设置.

(编辑:李大同)

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

    推荐文章
      热点阅读