удар: синтаксическая ошибка: неожиданный конец файла

Betcha я пропустил a fi где-нибудь.

Я сделал.

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

вот 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

(в основном это смолит то, что Вы передаете его, но я сверхусложнил его.)

не уверенный, если это полезно, но:

[~/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.
1
задан 28 October 2017 в 22:26

1 ответ

Вы не закрылись два if операторы с fi:

  • один запуск в строке 36

  • один запуск в строке 38

Делают зажим как:

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
4
ответ дан 3 December 2019 в 06:59

Другие вопросы по тегам:

Похожие вопросы: