What does the line “#!/bin/sh” mean in a UNIX shell script?

后端 未结 5 1810
暗喜
暗喜 2020-11-28 18:59

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

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

Can anyone ple

5条回答
  •  天命终不由人
    2020-11-28 19:37

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

    e.g.

    #!/usr/bin/perl   <--perl script'
    #!/usr/bin/php <-- php script
    #!/bin/false <--- do-nothing script, because false returns immediately anyways.
    

    It's implemented as a comment so that anything coming in that line will not "relevant" to the interpreter specified. e.g. all scripting languages tend to understand that a line starting with # is a comment, and will ignore the !/usr/bin/whatever portion, which might otherwise be a syntax error in that particular language.

提交回复
热议问题