What is a Shell Script?
A script, or file that contains shell commands, is a shell program. You can create a shell script using the editor supplied with your operating system such as vi editor.
Different ways to run as shell script:
There are mainly three different ways of running a shell script but before running a script you should have execute permissions on the script which can be assigned explicitly if you don't have permissions to execute i.e., by executing chmod +x scriptname at command prompt.
a. Ex: $ . yourscript.ksh.
This method of running a script is called the "dot" (.) method of running a script. The "dot" method of running a script causes the commands in the script to be run as if they were part of your login session.
b. Ex: $ yourscript.ksh.
This method is called "just the name" method which causes the shell to do a series of things. First, it runs another copy of the shell as a subprocess. The shell subprocess then takes commands from the script, runs them, and terminates, handing control back to the parent shell.
c. Ex: $ yourscript.ksh &.
& makes the command run in the background, which is really just another term for "subprocess". This method of running a shell script is similar to that method as in above point b. But there is a basic difference in this method you have control of your terminal or workstation while the command runs -- you need not wait until it finishes before you can enter further commands.
Below is a figure which depicts different ways of running a script i.e., here the script name is fred:
Figure 4-1. Ways to run a shell script
No comments:
Post a Comment