Why is my safe_rm shell script deleting after I test that safe_rm isn't being deleted?
Hello Everyone!
I am creating a bash script to ensure that the file that the user creates is being "deleted" (its moving the file to the recycle bin which is $HOME/deleted). In my attached code, steps 1-6 run the way that it is supposed to run. However, when I reach my last part to test that the file being "deleted" isn't safe_rm, it shows the error message that I created and I gave it the correct exit status but my whole script deletes. Luckily I have copies of it but I am wondering why its doing it. I've tried using readlinks but it appears to work for loops and my code isn't supposed to have any. I've attached a copy of my script. The issue that I am having is at #7. Am I supposed to add wild cards to my script to prevent deletion? Any suggestions and tips are greatly appreciated. Thank you very much everyone! Code:
#!/bin/bash |
It doesn't delete it after the "final_testing" test. It deletes it before it does that test.
Also, I notice a syntax error: Code:
if [ "$1"== *'safe_rm' ] ; |
Thank you for your feedback. I rearranged the order and my script stopped deleting. Thank you!
|
Have $1 in quotes if it's in command arguments, to prevent it from expansion.
Code:
movefile_inode "$1" Code:
if [ ! -e "$1" ] Code:
if [[ $1 == *'safe_rm' ]] Code:
fileName=$1 $1_ is not clear, better have Code:
echo "${1}_$inode:$path" Code:
echo "$1"_"$inode:$path" |
do not use the keyword readlink as a variable
|
Quote:
|
Quote:
sooner or later |
Quote:
Quote:
|
All times are GMT -5. The time now is 07:48 AM. |