Thursday

Shell Scripting

Writing a series of command for the shell to execute is called Shell Scripting. It can combine lengthy and repetitive sequences of commands into a single and simple script, which can be stored and executed anytime. This reduces the effort required by the end user.

Create a file using a vi editor(or any other editor).  Name  script file with extension .sh. Start the script with #! /bin/sh
Write some code.
Save the script file as filename.sh
For executing the script - $filename.sh

“#!” is an operator called shebang which directs the script to the interpreter location. So, if we use“#! /bin/sh” the script gets directed to the bourne-shell.


#comment - the syntax to add a comment.


Shell Variables- There are some special predefined variables available when a shell script is running.

$0 - name of currently running script
$# - number of arguments given to this script
$1, $2...$9 - $n is nth argument, and it is undefined if there is no nth argument.
$$ - PID of the script.

No comments:

Post a Comment

Followers