What does #!/bin/bash and #!/bin/sh mean and the difference

Source: Internet
Author: User
Tags posix
Respect for the original works, Ming: This post for the excellent post integration
One, meaning
#!/bin/sh refers to this script using/bin/sh to interpret execution, #! is a special notation, followed by the path to the shell that interprets the script.
In fact, the first sentence of the #! is the Interpreter program path to the script, the content of the script is interpreted by the interpreter, we can use a variety of interpreters to write the corresponding script.
For example,/bin/csh scripts,/bin/perl scripts,/bin/awk scripts,/bin/sed scripts, even/bin/echo, and so on.
#!/bin/bash the same.
Second, the difference
The/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 ported bash from NetBSD to Linux and renamed it the Dash (Debian almquist Shell),
It is recommended that you point the/bin/sh to it for faster script execution speed. The Dash shell is much smaller than the bash shell and is compliant with the POSIX standard
Ubuntu inherits Debian, so the default is the dash Shell, starting with Ubuntu 6.10.

It should be said that although/bin/sh and/bin/bash are largely indistinguishable, there are still different criteria.
Scripts marked as #!/bin/sh should not use any of the features that POSIX does not prescribe (such as let commands, but #!/bin/bash can).
Debian used/bin/bash change/bin/dash to use less disk space, provide less functionality, and get faster speeds.
But then there was a run problem with the shell script test. Because shell script (shell scripts), which could have been run under the bash shell,
Under/bin/sh, there will be some unexpected problems, not 100% concurrent use.

The above can be understood, using the man sh command and the Man Bash command to observe, you can find that SH itself is the dash, also better explain the changes after the integration of the Debian system.
It can be said that #!/bin/sh is a shortened version of #!/bin/bash.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.