“#!/bin/sh"行是什么意思?在 UNIX shell 脚本中是什么意思? [英] What does the line "#!/bin/sh" mean in a UNIX shell script?

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

问题描述

我正在阅读一些 shell 脚本教程,并找到了以下示例程序:

I was going through some shell script tutorials and found the following sample program:

#!/bin/sh
clear
echo "HELLO WORLD"

谁能告诉我开头的注释 #!/bin/sh 的意义是什么?

Can anyone please tell me what the significance of the comment #!/bin/sh at the start is?

推荐答案

它被称为 shebang,它告诉父 shell 应该使用哪个解释器来执行脚本.

It's called a shebang, and tells the parent shell which interpreter should be used to execute the script.

#!/bin/sh <--------- bourne shell compatible script
#!/usr/bin/perl  <-- perl script
#!/usr/bin/php  <--- php script
#!/bin/false <------ do-nothing script, because false returns immediately anyways.

大多数脚本语言倾向于将#开头的行解释为注释,并且会忽略下面的!/usr/bin/whatever 部分,否则可能会导致解释语言中的语法错误.

Most scripting languages tend to interpret a line starting with # as comment and will ignore the following !/usr/bin/whatever portion, which might otherwise cause a syntax error in the interpreted language.

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

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