1
#!/bin/bash
echo "Are you sure you want to move this file to the Recycle Bin?" "(Yes/No)"
read ans
case "$ans" in
        Yes) echo "$(readlink -f $1)" >> "$HOME/TrashLog" && mv "$1" "$HOME/my-documents/mydir01/Trash" ;;
        No) echo "File was NOT deleted and remains. ";;
esac

This script moves a file to a trash folder in which acts as a recycling bin. The 2nd script I'm trying to make should take the location of the original file (stored in TrashLog as a file path) and restore the file to its original location. Here's what I had so far (which isn't working).

#!/bin/bash
restore=$(find my-documents/* | grep $1)
filename=$(readlink -f $restore)
mv -i "$filename" "$(grep $1 $HOME/TrashLog)"
Gilles 'SO- stop being evil'
  • 807,993
  • 194
  • 1,674
  • 2,175
Craig
  • 31
  • 4
  • What is the issue? Does it move the wrong file? Do nothing? Print an error message? Poison your coffee? – Gilles 'SO- stop being evil' Nov 25 '14 at 22:31
  • ah sorry - i get an error along the lines of... find: `my-document/*': No such file or directory readlink: missing operand Try 'readlink --help' for more information. mv:cannot stat `/root/my-documents/mydir01/derp: no such file or directory" – Craig Nov 25 '14 at 22:32
  • Probably not your issue, but: [always use double quotes around variable substitutions](http://unix.stackexchange.com/questions/131766/why-does-my-shell-script-choke-on-whitespace-or-other-special-characters) — and even `grep -e "$1"` isn't very reliable since it'll pick up parts of file names. If you wanted to specify a file by a regular expression, use `find -name "$1"` – Gilles 'SO- stop being evil' Nov 25 '14 at 22:33
  • I think I understand - the 2nd script is supposed to take the filepath being stored in "TrashLog" and use that to restore the file to that location. If i'm making sense? – Craig Nov 25 '14 at 22:34
  • I even tried googling the error message, couldn't really make head nor tail of it. – Craig Nov 25 '14 at 22:39
  • Not intending to spoil your programming fun, but [there is already a freedesktop.org compatible command line implementation of a trash can](https://github.com/andreafrancia/trash-cli). It's Python, though. – Marco Nov 25 '14 at 22:43
  • ah, looks pretty complex for me - i really just need to do a restore based on what i've done for now :D – Craig Nov 25 '14 at 22:57

0 Answers0