DistributedNetworks DistributedNetworks


Shell Processes   «Prev  Next»
Lesson 6 Three ways to run a shell script
Objective Distinguish the three ways to run shell script.

Three ways to run a Unix Shell Script

Distinguish between the three ways to run a shell script.
  1. We have been running shell scripts by typing in the name of the script at the command line.
  2. There are two other techniques you can use to run a shell script.
  3. Each technique has an advantage and is appropriate in specific circumstances.
  4. The chart below lists three techniques used to run the script called myscript and the file permissions and process relationships used by the technique
  5. Would it be possible and appropriate to give these techniques names instead of just numbers?
  6. It seems it would make them easier to refer to in the text.
  7. Could they be called something like "script name," "shell path," and the 'dot command"
Can you think of anything?
Or do you think we should just keep the numbers? The numbers are alright for talking about this in this lesson, but may be confusing if we refer to these techniques in other places. More confusing if you do not have this table right in front of you.

Technique number Command permissions Subprocess created?
1 Myscript r-x Yes--runs as a child process of the current shell
2 /bin/sh myscript r-- Yes--runs as a child process of the current shell
3 . myscript r-- No--runs inside the current shell

Technique 1: The most common way to run a shell script, has the advantage of looking like other UNIX commands. This technique will be most comfortable to UNIX users. Use this technique unless you have a reason to use one of the others.
Technique 2: Which requires you to type in the name of the shell that the script was written for, is the most secure way to run a script. This technique, which is discussed in a later module, forces the script to be run in the shell you type on the command line.
Technique 3: uses the shell dot (.) command. This command works for the Bourne and Korn shells, but will not work if you are using a C shell. It tells the shell to read the commands from a script and run them in the current shell. Use this technique if your script contains variables that you want to include in your current shell. This technique is commonly used when you make changes to the .profile file in your home directory. Since .profile contains definitions of variables used in all the shells, run technique three on the file if you make a change.
The next lesson examines a method for indicating the shell for which your script is written.