1

Betcha I missed a fi somewhere.

I did.

[~/bin]: ./trashing_rm.sh
./trashing_rm.sh: line 70: syntax error: unexpected end of file
[~/bin]: 

here's trashing_rm.sh:

#echo $@ #dbg

function help(){
    if [[ $2 = "--help:setup" ]]; then
        echo "`basename $0` --setup :"
        echo "appends to your bashrc (found at ~/.bashrc) the following line:"
        echo "\"alias rm='$0'\""
        echo "by executing this command:"
        echo "echo \"alias rm='$0'\" >> ~/.bashrc"
        exit 0 #don't print the other help.
    fi
    echo -e "\e[01m-- `basename $0` :: help --\e[00m"
    echo
    echo    "`basename $0` --help         : this help page"
    echo -e "`basename $0` <\e[04mfile\e[00m>         : trash \e[04mfile\e[00m to ~/TRASH.tar"
    echo    "`basename $0` -r | --recover : extract trash to ~/recovered-trash"
    echo    "`basename $0` --setup        : append some stuff to your .bashrc ( \"--help:setup\" )"
    echo "Return status:"
    echo "0 : No problems; file added to ~/TRASH.tar"
    echo "1 : File not found"
    echo "2 : minor problems - ~/TRASH.tar not found"
    echo "3 : printed help message"
    echo
    echo "* if this script is aliased to 'rm', do '/bin/rm' for the builtin remove util."
    echo
    echo "The source file is located at: $0"
    exit 0
}

if [[ $1 = "--help" ]]; then
    help
fi
###################################################

if [[ $1 = "--recover" ]]; then
    if [[ -e ~/TRASH.tar ]]; then
        #create recovered-trash if it doesn't exist.
        if [[ -d ~/recovered-trash ]]; then
            mkdir ~/recovered-trash
        cp ~/TRASH.tar recovered-trash
        tar -xf ~/recovered-trash/TRASH.tar
        rm ~/recovered-trash/TRASH.tar #remove the copy
        echo "trash file extracted to ~/recovered-trash"
    else
        echo "no trash file found :("
fi

if [[ ! $1 ]]; then #we aren't passed anything
    echo "What do you want to trash?  [do -? for help]"
    exit 0
fi


if [ ! -e $1 ]; then #file doesn't exist
    echo "$0 : error 1: file '$1' not found"
    exit 1
fi


if [ -e ~/TRASH.tar ]; then #if trash file already exists
    tar -r -f ~/TRASH.tar $1
    /bin/rm $1 #if this script is aliased to 'rm',
               #we call ourselves if we do 'rm'.
else
    tar -c -f TRASH.tar $1
    /bin/rm $1
fi

exit 0

(basically, it tars whatever you pass it, but i've overcomplicated it.)

not sure if this is helpful, but:

[~/bin]: bash --version
GNU bash, version 4.2.25(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2011 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
  • i haven't done --setup yet, FYI. – Blacksilver Dec 20 '15 at 4:46
4

You have not closed two if statements with fi:

  • one starting at line 36

  • one starting at line 38

Make the chuck as:

if [[ $1 = "--recover" ]]; then
        if [[ -e ~/TRASH.tar ]]; then
                #create recovered-trash if it doesn't exist.
                if [[ -d ~/recovered-trash ]]; then
                    mkdir ~/recovered-trash
                fi
                cp ~/TRASH.tar recovered-trash
                tar -xf ~/recovered-trash/TRASH.tar
                rm ~/recovered-trash/TRASH.tar #remove the copy
                echo "trash file extracted to ~/recovered-trash"
        else
                echo "no trash file found :("
        fi
fi
  • 1
    Wow. that literally took less than 5 miniutes. thank you. will hit the accept button in 7 miniutes when it lets me. :) ( +1 awesome point ) – Blacksilver Dec 20 '15 at 4:49

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.