File Handling program by Rohit Nandagawali
File Hadling program using shell scripting Rohit NandagawaliRohit143
sh
4 years ago
1.4 kB
18
Indexable
#! /bin/bash
echo ======File Handling Program=======
echo enter file name
read file
if [ -e $file ];
then
echo "Yes,file exist"
echo --------------------
echo Choose What you want to do with file
echo " 1.Rename \n 2.Copy \n 3.Remove\n 4.Exit"
read choice
case $choice in
"1")
echo "You selected to Rename" ;
echo "Enter new name";
read new_name
mv $file $new_name #rename
echo "File Renamed to $new_name Succefully";;
"2")
echo "You selected to Copy";
echo Enter target file name:
read targ
if [ ! -f $targ ]
then
echo File $targ does not exist here
echo creating $targ..
echo coping...
cp $file $targ #copy
echo copied successfully
else
echo Cannot copy $file to $targ
echo $targ already exist,Cannot overwrite $targ
fi;;
"3")
echo "You selected to Remove";
echo "Do you really want to remove $file ?";
echo "y/n"
read yes_no
case $yes_no in
"y")
rm $file; #remove
echo File removed Succefullly;;
"n")
echo File removal Operation cancelled!!;
exit 2;;
*)
echo "Invalid Option,redirecting to Menus";
sh file_handle.sh;;
esac;;
"4")
exit 2;;
*)
echo Please select valid Option;
sh file_handle.sh;;
esac
else
echo "file does not exist"
fiEditor is loading...