如何使用 echo 命令打印 #!/bin/bash
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22797530/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to print #!/bin/bash using echo command
提问by Seff
I have tried the escape character but it doesn't seems works with !. I need this to auto-configure packages using scripts.
我已经尝试过转义字符,但它似乎不适用于! . 我需要它来使用脚本自动配置包。
回答by that other guy
!
is magic in a default interactive bash session, but not in scripts (set +H
to disable in an interactive prompt). In any case:
!
在默认的交互式 bash 会话中是魔术,但在脚本中不是(set +H
在交互式提示中禁用)。任何状况之下:
echo '#!/bin/bash'
回答by Digital Trauma
Or with no quotes and escaping the #
and the !
:
或者没有引号并转义#
和!
:
echo \#\!/bin/bash
回答by Avi Das
printf should work too:
printf 也应该工作:
printf '#!/bin/bash\n'