Bash脚本:#!/bin/bash是什么意思? [英] Bash Script : what does #!/bin/bash mean?

查看:101
本文介绍了Bash脚本:#!/bin/bash是什么意思?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在bash脚本中,第一行的#!/bin/bash 是什么意思?

In bash script, what does #!/bin/bash at the 1st line mean ?

更新:#!/bin/bash #!/bin/sh 之间是否有区别?

UPDATE: Is there a difference between #!/bin/bash and #!/bin/sh ?

推荐答案

即称为 shebang ,它告诉Shell执行时使用什么程序解释脚本.

That is called a shebang, it tells the shell what program to interpret the script with, when executed.

在您的示例中,脚本将由 bash shell解释和运行.

In your example, the script is to be interpreted and run by the bash shell.

shebang的其他示例是:

Some other example shebangs are:

(来自维基百科)

#!/bin/sh — Execute the file using sh, the Bourne shell, or a compatible shell
#!/bin/csh — Execute the file using csh, the C shell, or a compatible shell
#!/usr/bin/perl -T — Execute using Perl with the option for taint checks
#!/usr/bin/php — Execute the file using the PHP command line interpreter
#!/usr/bin/python -O — Execute using Python with optimizations to code
#!/usr/bin/ruby — Execute using Ruby

还有一些我可以想到的其他内容,例如:

and a few additional ones I can think off the top of my head, such as:

#!/bin/ksh
#!/bin/awk
#!/bin/expect

例如,在具有bash shebang的脚本中,您将使用bash语法编写代码;而在带有Expect shebang的脚本中,您可以使用Expect语法对其进行编码,依此类推.

In a script with the bash shebang, for example, you would write your code with bash syntax; whereas in a script with expect shebang, you would code it in expect syntax, and so on.

响应更新的部分:

这取决于系统上/bin/sh 实际指向的内容.通常,它只是到/bin/bash 的符号链接.有时,可移植脚本是用#!/bin/sh 编写的,只是表示它是一个shell脚本,但它使用的是/bin/sh 所引用的任何shell.特定系统(可能指向/bin/bash /bin/ksh /bin/zsh )

It depends on what /bin/sh actually points to on your system. Often it is just a symlink to /bin/bash. Sometimes portable scripts are written with #!/bin/sh just to signify that it's a shell script, but it uses whichever shell is referred to by /bin/sh on that particular system (maybe it points to /bin/bash, /bin/ksh or /bin/zsh)

这篇关于Bash脚本:#!/bin/bash是什么意思?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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