Java source code era Dry Share | Shell Scripting learning portal, just two steps, you learn to pack!

A recent study shell programming, for the first line of a shell script used to specify the script interpreter code in the end have designated interpreter did not play the role of wonder, such as: #! / Bin / bash

The Internet to find a lot of information, also found online actually divided the two factions, some people think that #! / Bin / bash not play a role, as in shell scripts # indicates a comment meant, while others think It is active, but did not give a convincing reason, no way, I had to make their own testing.
1. First of all I would like to create a file named test.sh the shell, which reads as follows

Java source code era Dry Share | Shell Scripting learning portal, just two steps, you learn to pack!

The second line of the script file using bash syntax does not support the POSIX standard, so if this file is bash interpreter to run, it can run properly, and if the change is sh interpreter, it will report a syntax error

Modify permission test.sh

Java source code era Dry Share | Shell Scripting learning portal, just two steps, you learn to pack!

Then direct execution test.sh

Java source code era Dry Share | Shell Scripting learning portal, just two steps, you learn to pack!

You can see, the script runs successfully, no error, then I will be the first line changed to #! / Bin / sh

Java source code era Dry Share | Shell Scripting learning portal, just two steps, you learn to pack!

2. Then run
Java source code era Dry Share | Shell Scripting learning portal, just two steps, you learn to pack!

This time it reported a syntax error
can be concluded, shell scripts the first line of the script interpreter is specified does work, but it is worth noting that, when we use the designated interpreter to run the script, we script the first line of the file will fail, such as by running the script file name bash + way, so even if I specified in the file is the sh interpreter, the result will still be run as bash interpreter.
(This article was written by the original source era technology teacher, please indicate the source)

Guess you like

Origin blog.51cto.com/14497209/2439782