The Guide to Shell Scripting: The Basics

We have already written about Shell scripting ,What is its uses, what are various type of shells and what are positional parameters

What is Shell and Shell Scripts

In this post, I will  write about creating first shell scripts for the beginners

First of all important  things for the shell scripts

Scripts must contain complete documentation
Each script must contain internal comments that document
The name of the script
The purpose for the script
The name of the author(s)
The date the script was written
The date(s) the script was modified.
The name of each script must reflect its use
Each script must have a suffix that describes the script, for example “.sh” for Bourne shell scripts, “.ksh” for Korn shell or “.cgi” for Common Gateway Interface scripts.
Lets create the first shell script


# This script displays the date, time, username and
# current directory.
echo “Current date and time is:”
echo “Your username is: `whoami` \\n”
echo “Your current directory is: \\c”

echo “Your system name is :`hostname`\\n”



Explanation of each line in the scripts is given below

  1. #!/bin/ksh as the first line of the script .It is used to tell the script to execute with ksh shell

2. The second two lines beginning with a hash (#) are comments and are not interpreted by the shell.

3.Use comments to document your shell script.

4. The backquotes (`) around the command whoami illustrate the use of command substitution.The command whoami will be executed and output will be printed at that position. Whoami tells the user information

5. The \\n is an option of the echo command that tells the shell to add an extra carriage return at the end of the line.

6.The \\c tells the shell to stay on the same line.

7.  hostname command gives the hostname of the system