The first time I learned shell programming, I read the article that the shell program must start "#! /Bin/sh.
Although I know that all statements starting with "#" in shell are comments, I never think "#! /Bin/sh is also a comment, just as there is no doubt that a C program must have a main function.
But some time ago I heard that "#! /Bin/sh "is also a comment and dispensable. At that time, I thought it was a failure and I couldn't even tell the basic syntax.
I borrowed a book a few days ago, so I really got to know me "#! /Bin/sh ".
Shell programming is annotated with "#", but "#! /Bin/sh ", but not.
"#! /Bin/sh "is the shell declaration, indicating that you are using the shell type and its path.
If no declaration is made, the script will be executed in the default shell. The default shell is defined by the user's system as the shell for executing the shell script.
For example, if the script is written to run in Korn Linux and the C shell CSH is run by default, the above script may fail to be executed.
Therefore, we recommend that you set "#! /Bin/sh "is the same as the main function in C language. It is required to write shell to make Shell programs more rigorous.
That is :#! /Bin/sh indicates that the script is interpreted and executed using/bin/sh ,#! Is a special identifier, followed by the path of the shell that explains the script.
In fact, the first sentence #! It is the interpreter program path for the script. The content of the script is explained by the interpreter. We can use various interpreters to write the corresponding script.
For example, the/bin/CSH script,/bin/perl script,/bin/awk script,/bin/SED script, And/bin/ECHO script.
Can we write a/bin/ECHO script file? Let's try it. The following is an example:
Code:
#! /Bin/ECHO-e
This only has one line of Program (in fact it can only be one line, Echo program is not designed as a programming language like awk, can be written as a source program file) named myecho, add the permission and execute it:
Code:
$./Myecho "Hi \ A"./myecho hi
If your echo supports the-E Option and your work environment is still quiet, you should also hear the crisp terminal ring when you get the above results. But such a program is useless.