|
||
Lesson 7
Objective
|
Specifying the shell in a script />
Using #! on the first line of a script. |
|
Eliminate the word notation so there will not be confusion here.
To indicate the shell for which a script is written, use the following on the first line of your script: #! /bin/sh ok of the shell to be used. How #! works
When you run the script, the shell looks for #! on the first line. After finding it, your script runs using the indicated shell
Technique number one only
Does that mean it first starts the shell? Or does itnothave tostart a shell in order torun a script with it? I purposely did not explain this in detail because it gets involved. It wont matter to someone writing a script they just need to know that the shell is indicated on the #! Line. . Using #! on the first line of your script ensures that your script will run using the correct shell. If this line is not inserted at the top of your script, then your shell might assume you are using Bourne, Korn, or C shell without any consistency. Its better to know which shell your script will be run under by including the #! on the first line.
Of the three techniques
[[Three ways to run a shell script]] listed in the previous lesson, only technique number one (typing the script name in on the command line)
reads the first
line of the file to check for the #!. The other two techniques see the #! line as a commentany particular reason that this happens,
or is that totally irrelevant?
The next lesson looks at the shell PATH variable.
Just theway the techniques work. |
||
|
|
||