Wednesday, September 3, 2014

[Quick Tips] : How To Use case in Bash Script, Example

How To Use case in Bash Script, Example

How To Use case in Bash Script, Example
This is only an example.
#/bin/bash
echo “Give Full Path where the file is located”
read pth
echo “Give the file name”
read fle
if [ -f $pth/$fle ];then
echo “$fle file is found in $pth”
else
echo “$fle file not found in $pth”
echo “U r going to exit in 2seconds”
sleep 2
exit
fi
echo “Do u want to delete the file (Y/N)”
read xyz
case $xyz in
Y|y) rm -fr $pth/$fle;;
[Yy][Ee][Ss]) rm -fr $pth/$fle;;
N|n) exit;;
[Nn][Oo]) exit;;
*) exit;;
esac

No comments: