General TC > Programming & Scripting - Unofficial

trash

<< < (2/2)

jpeters:

--- Quote from: mikshaw on November 23, 2009, 09:01:48 AM ---
--- Code: ---  while [ $# -ge 1 ];do
     sudo mv ${1} ${TRASH}
     shift
   done
--- End code ---
Could this be done in just one command rather than a loop?  The mv command supports mulitple files.

--- Code: ---sudo mv "$@" ${TRASH}
--- End code ---

The directory test is using a specific path rather than $TRASH

The delete confirmation could be improved.  If you just press enter when the "y" is visible, you get an error.  It is common to have a default selection displayed in uppercase -- Delete? (y|N) -- which allows the user to just press enter to accept the default.  The error can be avoided either by first testing for the existence of $RESPONSE before comparing it to "y", or by using case instead of if.

Personally I wouldn't delete the trash directory, only its contents...but I can see reasons for doing that.

--- End quote ---

Thanks mikshaw. Always great to have your expertise.  I removed the loop and fixed the bug, as you suggested. The (y|N) looks like (yIN) on my computer, so others can add that if they want..although it's not needed.  I  kindof like deleting the whole directory, since it's easier to move around, etc., but that could be edited:  "y" )  sudo rm -R ${TRASH}/*  ....

Navigation

[0] Message Index

[*] Previous page

Go to full version