Always thought that in the shell script # is to represent the annotation function, also at the beginning of the script #!/bin/sh also just tell the user this is a shell script, and recently checked the next, only to find that this is not the meaning, share the following article.
Transferred from: http://www.cnblogs.com/EasonJim/p/6850319.html
First, meaning
#!/bin/sh means that this script uses /bin/sh to interpret execution,#! is a special identifier followed by the path to the shell that interprets this script .
$ cat/etc/shells can view the shell format supported by the system
In fact, the first sentence of #! is the script interpreter program path, the content of the script is interpreted by the interpreter, we can use a variety of interpreters to write the corresponding script.
such as /bin/csh scripts,/bin/perl scripts,/bin/awk scripts,/bin/sed scripts, even /bin/echo , and so on.
#!/bin/bash .
Second, the difference
/bin/sh in the Gnu/linux operating system is a symbolic link to Bash (bourne-again Shell) , but given that bash is too complex, someone puts bash Ported from NetBSD to Linux and renamed to Dash (Debian almquist Shell), it is recommended to point /bin/sh to it for faster script execution. The Dash shell is much smaller than the bash shell and is POSIX compliant.
So that is in Ubuntu can be considered /bin/sh is/bin/dash, if you intend to use bash, you can directly/bin/sh soft links to/bin/bash.
Ubuntu inherits Debian, so the default is dash Shell starting with Ubuntu 6.10.
It should be said that although the/bin/sh and /bin/bash are largely indistinguishable, there are still different standards. Scripts marked as #!/bin/sh should not use any POSIX -defined features (such as Let commands, but #!/bin/bash can). Debian used /bin/bash to change the /bin/dashto use less disk space, provide less functionality, and get faster speeds. However, there was a running problem after the shell script test. Because of the shell script that was originally run under the bash Shell , there are some unexpected problems under /bin/sh , not 100%.
The above can be understood, using the man sh command and the man Bash command to observe, you can find that sh itself is Dash, It is also better to explain the changes after the integration of the Debian system.
Above reference: http://blog.chinaunix.net/uid-27037833-id-3431985.html
[Shell] What does the Linux script start with #!/bin/bash and #!/bin/sh mean and the difference