“#!/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.