so this function basically runs similar to rm -i command and the arguments are passed while executing (eg. bash script_Name test.txt).
rm -i $file does ask me to confirm y or n. If "y" then the script run as expected and sends the file's path to another file (.restore.info) in the home directory. But when "n" is entered the path still goes to another file (.restore.info) and does not delete the file (test.txt) from the current directory. For both "y" and "n" the file (test.txt) does copies cp to a folder (recyclebin) in home directory.
My question is, can I do it in such a way that only when the user hit "y", all the other lines should be executed (cp and >> to .restore.info)?
file=$1
if [ -f $file ]
then
if [ ! -e $file ] ; then
echo "FILE DOES NOT EXIST - OPERATION ABORTED"
fi
inode=$(ls -i $file | cut -d " " -f1)
#filename=$(basename $file)
newfilename=$file\_$inode
fixedPath=$(readlink -fn $file)
echo $newfilename:$fixedPath >> $HOME/.restore.info
cp $file $HOME/recyclebin/$newfilename
rm -i $file
if [ ! -e $file ] ; then
echo "Recycling $file please wait"
fi
fi