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

为什么我不能回应人物#!用bash中的字符串?

发布时间:2020-12-15 18:59:31 所属栏目:安全 来源:网络整理
导读:参见英文答案 echo “#!” fails — “event not found”5个 我有一个小的bash脚本应该移动到我的主目录,创建一个文件,回收一些垃圾,并使其可执行.这就是它的样子: cd ; touch tor.sh; echo "#!/bin/bashn/usr/local/bin/tor" tor.sh; chmod +x tor.sh 但
参见英文答案 > echo “#!” fails — “event not found”5个
我有一个小的bash脚本应该移动到我的主目录,创建一个文件,回收一些垃圾,并使其可执行.这就是它的样子:
cd ; touch tor.sh; echo "#!/bin/bashn/usr/local/bin/tor" >> tor.sh; chmod +x tor.sh

但这仍然在回声中打破,抱怨“未找到事件”?出于某种原因,我决定尝试这个并且它有效:

cd ; touch tor.sh; echo -e "x23x21/bin/bashn/usr/local/bin/tor" >> tor.sh; chmod +x tor.sh

为什么我必须用十六进制和-e替换这两个字符(shebang?)?有一个更好的方法吗?

这不是一个错误,它与shebang无关,只是感叹号.
Enclosing  characters  in double quotes preserves the literal value of
all characters within the quotes,with the exception of $,`,,and,when  history expansion is enabled,!.

所以要么逃避它,使用单引号,要么关闭历史扩展.

例如

> echo "How dare you put an '!' in this string?"
bash: !: event not found
> set +o histexpand
> echo "How dare you put an '!' in this string?"
How dare you put an '!' in this string?

(编辑:李大同)

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

    推荐文章
      热点阅读