Running a Shell Script

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 previous 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.

Figure 10.2. Running a script is as easy as typing sh plus the filename of the script.


To Run a Script:

  • sh myscript

    At the shell prompt, type sh (or the name of the shell, like ksh or csh, you want to run the script) followed by the name of the script. In this case, you’re really just telling sh to run and to use the list of commands in the myscript file. You’ll see the results of the script—in this case, words appear onscreen, as shown in Figure 10.2.

✓ 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 essential only when the script is executable, as in the following section.


..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.86.172