且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

“#!/bin/sh"行是什么意思?在 UNIX shell 脚本中是什么意思?

更新时间:2022-06-18 04:30:26

它被称为 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.