echo "1.List of File and directory\n2.Copy file\n3.Rename File"
echo "\nSelect one operation"
read ch
case $ch in
1)
echo "===== List of file ====="
echo "============================="
ls -l
echo "============================="
;;
2)
echo "==== Copy Operation ===="
echo "Enter file name you want to copy"
read fn
if [ ! -f $fn ]
then
echo "Sorry this file is not exist"
else
echo "enter location you want to copy"
read path
if [ ! -d $path ]
then
echo "Invalid path"
else
cp $fn $path
echo "Copy success"
fi
fi
;;
3)
echo "=== rename operation ====="
echo "Enter file name you want to rename"
read fn
if [ ! -f $fn ]
then
echo "Sorry this file is not exist"
else
echo "Enter file new name"
read nn
if [ $nn -eq $fn ]
then
echo "Old name and new name is not same"
else
mv $fn $nn
echo "Rename success"
fi
fi
;;
*)
echo "Invalid Operation"
esac
Write shell script to list, copy & rename file using select case.
Comments
One response to “Write shell script to list, copy & rename file using select case.”
-
show me notes
Leave a Reply