#code goes here.
#!/bin/bash
echo -n "Enter the filename : ";
read myfile;
echo -n "Are you sure (Yes/No)?"
read confirm;
#Checking the entered file type
if [ -f $myfile ]; then
value="File"
elif [ -d $myfile ]; then
value="Directory"
else
value="Special file"
fi
#user confirmation for deletion
confirm="$(echo ${confirm} | tr 'A-Z' 'a-z')"
if [ "$confirm" == "yes" ]; then
#deleting the file/directory
[ -f $myfile ] || [ -d $myfile ] && /bin/rm -r $myfile && echo "$value $myfile has been deleted"|| echo "Error - Unable to locate the file $myfile"
else
echo " Program exiting...."
fi
#------------------------------
No comments:
Post a Comment