bash: erro de sintaxe: final inesperado do arquivo

1

Betcha perdi fi em algum lugar.

eu fiz.

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

aqui está 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

(basicamente, o que quer que você passe, mas eu o supercompliquei.)

não tenho certeza se isso é útil, mas:

[~/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.
    
por Blacksilver 20.12.2015 / 05:40

1 resposta

4

Você não fechou duas declarações if com fi :

  • um começando na linha 36

  • um começando na linha 38

Faça o mandril como:

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
    
por heemayl 20.12.2015 / 05:46