0

I'm new to Linux and I've written a script to move files to a specified folder (fake delete).
However it will only mv the file in the same folder as my script. Is there a way I can make this executable to delete any file no matter the location?

I.e.:

DELETE test ..(test is in ~/my-documents folder) (delete script in ~/my-applications/bin folder)

The script is below.

echo do you want to delete this? (yes/no) \n
read ans \n
case "$ans" in
  Y¦y¦yes ) echo "$readlink -f "$1")" >>"$HOME/DustbinLog" && mv "$1" "$HOME/my-applications/bin/dustbin";; 
  N¦n¦no echo "File not moved!";;     
esac
  • 2
    The shell can't guess where the file is, specially because there might be files with the same name in different folders. You have to specify the path to the file you want to delete. If it is in ~/my-documents run DELETE ~/my-documents/test. – IanC Nov 27 '16 at 00:47
  • 2
    Also, I think it might have been a mistake while writing the question (since you apparently tested the script and it worked on your current folder), but there are some mistakes in the code there. The newline characters, the or operator (should be |, not ¦), the second option from the case is missing a ). I also would use a default case in the "no" answer (*)). That way, if the user types anything but Y/y/yes the file won't be moved and the message will be prompted. – IanC Nov 27 '16 at 00:54
  • This might also interest you: http://askubuntu.com/q/213533/457562 – Nonny Moose Nov 27 '16 at 01:06
  • many thanks. yes your are right I miss typed my code on here. and thank you for the suggestion on the asterix .. – Yunus1979 Nov 27 '16 at 11:55

1 Answers1

0

I just needed to be in the pwd for the DELETE command to work or put the exact path name.. thanks..