What does the Linux script start with #!/bin/bash and #!/bin/sh mean and the difference

Source: Internet
Author: User
Tags posix

First, meaning

#!/bin/sh means that this script uses /bin/sh to interpret execution,#! is a special designator, which is followed by the path to the shell that interprets this script.

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.

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

What does the Linux script start with #!/bin/bash and #!/bin/sh mean and the difference

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.