Hey , guys I am new to shell programing ,, so need a help from you guys ...
I have to write a shell script that accepts file name or directory name from the user if it is a directory then throw an error if it is a file then give the user two options .
1.overwrite the content
2.append the content
Here is my program ..
echo " Enter the File name or Directory name"
read fname
if test -d $fname # we are checking fname is a directory or not
then # if it is a directory
echo " Please enter a file Not a directory "
else
echo " 1. Overwrite the contents of $fname "
echo " 2. Append the contents to your $fname "
read val
case $val in
1)
clear
echo "Write your content:"
cat > $fname
#read content
#echo $content> $fname
;;
2)
clear
echo "Write your content:"
cat >> $fname
#read content
#echo $content>> $fname
;;
*) # All other user input results in an usage message
clear
#echo Please choose alternatves 1, 2 or 3
sleep 2
;;
esac
fi
My problem is that I want to throw a message after the file is overwritten or appended without exiting the program
I have tried to use ctrl+c but it takes me out of the whole program .
Do correct me if I am wrong anywhere .