After you've created a script in your editor and saved the script file, your next step is to run it, which means to execute every command in the script in the order provided. (Yes, you did this in the last section, but we'll expand on it here.) As Figure 10.2 shows, you do this using the sh command (or the name of the shell you're using), followed by the name of the shell script you want to run.
To run a script:
sh myscript
Tip
Note that in this example, you're explicitly telling UNIX the name of the script to run (myscript). When you do so, the #! /bin/sh line at the top of the script in the previous section is technically superfluous. It's only essential when the script is executable, as in the following section.
[ejr@hobbes scripting]$ head -2 myscript #! /bin/sh # This is my first shell script [ejr@hobbes scripting]$ chmod u+x myscript [ejr@hobbes scripting]$ pwd ; echo $PATH /home/ejr/scripting /usr/local/bin:/bin:/usr/bin:/usr/X11R6/bin: /usr/local/games:/home/ejr/bin:/home/ejr/ scripting [ejr@hobbes scripting]$ myscript friendsjustfriends standing good [ejr@hobbes scripting]$ |
3.144.33.41