Shell Programming
Shell Programming
Ex:
grep “sales” emp.lst
Wild-Cards Matches
* Any number of characters including
none
? A single character
[ijk] A single character – either i, j, or k.
[x-z] A single character within the ASCII
range of x and z
[!ijk] A single character that is not an i, j, or
k
[!x-z] A single character that is not within
the ASCII range of x and z
# - Comment Character:
The Shell ignores all characters placed on its right.
Example:
$ grep “director” emp.lst >/home/vishal; echo$?
#!/bin/sh
if test $# –ne 2; then
echo “You did not enter 2 arguments”
else
grep “$1” $2 || echo “$1 not found in $2”
fi
$x=3; y=5
$expr 3 + 5
$expr $x - $y
$expr 3 \* 5
$expr 3 / 5
$expr $y % $x
Command substitution:
z =`expr $x + $y`
Incrementing value of a variable
x =`expr $x + 1`
Extracting a sub-string
Expr can extract a string enclosed by escaped character \
( and \)
$ stg = 2003
$ expr “$stg” : ‘..\(..\)’