Write shell script to list, copy & rename file using select case.

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

Comments

One response to “Write shell script to list, copy & rename file using select case.”

  1. rashi sharma Avatar
    rashi sharma

    show me notes

Leave a Reply

Your email address will not be published. Required fields are marked *