case expression in
pattern1 )
statements ;;
pattern2 )
statements ;;
...
esac
1
Source: thegeekstuff
if [ $# -lt 2 ]
then
echo "Usage : $0 Signalnumber PID"
exit
fi
case "$1" in
1) echo "Sending SIGHUP signal"
kill -SIGHUP $2
;;
2) echo "Sending SIGINT signal"
kill -SIGINT $2
;;
3) echo "Sending SIGQUIT signal"
kill -SIGQUIT $2
;;
9) echo "Sending SIGKILL signal"
kill -SIGKILL $2
;;
*) echo "Signal number $1 is not processed"
;;
esac
# Count number of lines matches
-i) echo "Number of lines matches with the pattern $2 :"
grep -c -i $2 $3
;;
# Count number of words matches
-c) echo "Number of words matches with the pattern $2 :"
grep -o -i $2 $3 | wc -l
;;
# print all the matched lines
-p) echo "Lines matches with the pattern $2 :"
grep -i $2 $3
;;
# Delete all the lines matches with the pattern
-d) echo "After deleting the lines matches with the pattern $2 :"
sed -n "/$2/!p" $3
;;
*) echo "Invalid option"
;;
esac
for filename in $(ls)
do
# Take extension available in a filename
ext=${filename##*\.}
case "$ext" in
c) echo "$filename : C source file"
;;
o) echo "$filename : Object file"
;;
sh) echo "$filename : Shell script"
;;
txt) echo "$filename : Text file"
;;
*) echo " $filename : Not processed"
;;
esac
done
read yno
case $yno in
[yY] | [yY][Ee][Ss] )
echo "Agreed"
;;
[nN] | [n|N][O|o] )
echo "Not agreed, you can't proceed the installation";
exit 1
;;
*) echo "Invalid input"
;;
esac