Introduction to Shell Scripting

Bash Shell scripting

———————

-What is a shell script?

. Shell script is a normal text file that contains commands to perform some specific tasks.

.Shell scripting is extensively used in system administration to automate routine task like creating backup, scanning disks etc.

.Shell scripts are also used to create simple applications.

Creating a Shell script

————————

before using this , use this command

#echo “Testing shell script”

# (hash is used to give comments in script0

#! (hash and exclamation is called she-bang) is used to specify interpreter’s path

Bash Shell scripting (contd…)

Options

1.         String operator

str1 [option] str2

= True if string is equal to string 2

! true if string1 is not equal to string2

-z Str – true if the string size is equal to zero

-n Str – true if the string size is not equal to zero

2.         Numeric operators

Num1 [option] num2

-eq – true if num1=num2

-ne – true if ,,   not = to

-lt – ,,   ,,  ,,  < ,,

-le – ,,  ,,   ,,  <= ,,

-gt – ,, ,,   ,,   > ,,

-ge – ,,  ..   ,, >= ,,

3. Logical operators

-a logical AND

-o ,,      OR

!  ,,      NOT

4 File operators

-e file – true if tjhe file exists

-f file  – ,,  ,,   ,,  ,, is a normal file

-d file ,,  ,,      if it is a dir

-h file ,,   ,,      ,,,   ,, symbolic link

-r file  ,,   ,,   ,,    ,,, if the file is readable

-w file true writable

-x file ,,         ,,   executable

-O file true if the file is effectivly owened by user owener of the file

-G file true if the file is effectivly owened by group owner of the file