Hi I'm creating a recycle bin script with the command name 'safe_rm'. I was wondering, how can I prevent the script from deleting its own file. I believe the readlink command is one solution however I'm not sure how to write it within the script.
Here is my current code
while [ $# -ne 0 ] do if [ ! -e "$1" ] ; then echo "File not found." elif [ -d "$1" ] ; then echo "Error. You have entered a directory." elif [ $1 = $(readlink -e ~/project/safe_rm) ] ; echo "Attempting to delete safe_rm - operation aborted" exit 0 else inode=` ls -i $1 | cut -d" " -f1 ` echo $1_$inode:$(readlink -e $1) >> /home/j.t/.restore.info mv $1 /home/j.t/deleted/$1_$inode echo "File '$1' has been moved to the recycle bin." fi shift done
The code which needs modifying is on line 8.