在没有shebang行的情况下编写Bash脚本 [英] Writing a Bash script without the shebang line

查看:61
本文介绍了在没有shebang行的情况下编写Bash脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在CentOS下编写了一个bash脚本,它执行得很好.在另一台计算机上,这是错误的.我一开始就忘记了shebang,但是为什么我的计算机上还不错呢? 我认为这是一个非常初学者的问题,但是我尝试了一下.谢谢.

I wrote a bash script under CentOS and it was executed well. On another computer it was wrong. I forgot the shebang at the beginning, but why was it good on my computer? I assume it's a very beginner question, but I gave it a try. Thanks.

已更新: 出现了另一个问题.用 ./filename.sh sh filename.sh 执行之间有什么区别?

Updated: Another question popped up. What's the difference between executing with ./filename.sh and sh filename.sh?

推荐答案

在脚本的开头没有shebang,将在调用脚本时在当前正在运行的任何shell中执行该脚本.如果您确定该脚本将从bash启动,而不是从任何其他shell(ksh,csh等)启动,则无需使用shebang,因为将启动同一解释器.

Not having a shebang in the beginning of your script will get it executed in whatever shell is currently running when the script was invoked. If you know for sure that the script will be launched from bash, and not from any other shell (ksh, csh, etc.), there is no need for a shebang, because the same interpreter will be launched.

这篇关于在没有shebang行的情况下编写Bash脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆