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 (#!)