Shebang symbols on Linux (#!)

Source: Internet
Author: User
Tags shebang

Students who use Linux or UNIX systems may not be familiar with the #! symbol, but do you really know it?

This article will give you a brief introduction of Shebang ("#!" ) This symbol.

First, the name of this symbol (#!) is called "Shebang" or "Sha-bang" (there are some other names, but I usually use these two).

Shebang This symbol is usually written at the beginning of the first line of the script in the UNIX system, which indicates the interpreter that executes the script file.

1. If this line is not #! in the script file, it will be executed by default using the current shell to interpret the script (i.e. $SHELL environment variable).

2. If the interpreter after #! is an executable file, the script is executed by passing the file name and its arguments as parameters to the interpreter.

3. If the interpreter specified by #! does not have executable permissions, an error "bad Interpreter:permission denied" will be given.
If the interpreter specified by #! is not an executable file, then the specified interpreter is ignored and handed over to the current shell to execute the script.

4. If the interpreter specified by #! does not exist, an error "bad interpreter:no such file or directory" will be given.
Note: After #! the interpreter, it is necessary to write its absolute path (for example: #!/bin/bash), it is not automatically to $path to find the interpreter.

5. Of course, if you use a command like "Bash test.sh" to execute the script, the #! line will be ignored and the interpreter is, of course, the bash explicitly specified in the command line.

Example: test.sh

View Code BASH
#!/bin/bashecho"Hello, world. " " Echo " Hello, ${1}. "

chmod a+x test.sh

./test.sh Jay (at runtime, actually/bin/bash/test.sh Jay)

The result is:

Hello, world.
Hello, Jay.

Transferred from: http://smilejay.com/2012/03/linux_shebang/

Main references:

Http://en.wikipedia.org/wiki/Shebang_ (Unix)

Http://people.csail.mit.edu/jaffer/Docupage/sharpbang.html

Shebang symbols on Linux (#!)

Related Article

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.