Hey mate, I finally got it working - cheers for all your help, I'm pretty sure my system will be safe from my error-prone ways.
haha yeah.. have fun
The code underneath works for me... but the file is not restored to its original location.. just to the working directory... any ideas?
I looked at the code, and then cried.. and then I went and rewrote it. It is not perfect, but it does work. Tested it.
function restfile() {
# First arg is the file to restore.
# Test if empty, give error if it is, give error.
if [ -z $1 ]; then
echo "Syntax is: restorefile filename destination";
else
# If they did specify a file, test for it in the trash.
if [ ! -f /home/username/trashbin/$1 ]; then
#does not exist
echo "The file does not exist in the trashbin.";
else
#does exist.
if [ ! -z $2 ]; then
#did they specify a place to move it to?
#If so, move it there
echo "Restoring $1 to $2";
mv /home/username/trashbin/$1 $2
else
# If not, then move it to the current directory.
echo "Restoring $1 to home directory.";
mv /home/username/trashbin/$1 .
fi
fi
fi
}
Put double quotes around all your $1 and $2 expressions. Otherwise, files with funny names or with spaces in them will create problems for the script.