[root@centos ~]# printf "#!/bin/sh\nsomething"
-bash: !/bin/sh\nsomething": event not found它无法将命令作为命令执行,因为它没有保存到命令历史记录中。
我必须稍微混淆一下杂技,这样它才能让我通过?
我试过这个:
[root@centos ~]# printf "%s!/bin/sh\nsomething" #
-bash: !/bin/sh\nsomething": event not found(也尝试了echo的同样效果)
发布于 2013-07-26 03:36:37
在交互式shell中,!用于历史替换。您可以使用\或将字符串放在单引号中转义:
printf '#!/bin/sh\nsomething'请参阅bash 历史扩展的文档。
如果您的实际应用程序将在脚本中,这将不是一个问题,因为在脚本中默认不启用历史记录。
如果您从未使用过历史扩展,则可以使用以下方法禁用历史字符:
export histchars=发布于 2013-07-26 03:37:29
井。这是我找到的一个解决办法:
[root@centos ~]# printf "#%s/bin/sh\nsomething" !
#!/bin/sh
something是的,必须是历史扩展才会扰乱它(提到event的错误是一个很大的线索)。
注意:我选择在我的脚本制作脚本中使用一个本地文档。转义字符串是可怕的。
https://stackoverflow.com/questions/17872463
复制相似问题