AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / ubuntu / 问题 / 711448
Accepted
SIGSTACKFAULT
SIGSTACKFAULT
Asked: 2015-12-20 20:40:31 +0800 CST2015-12-20 20:40:31 +0800 CST 2015-12-20 20:40:31 +0800 CST

bash:语法错误:文件意外结束

  • 772

我错过了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.
command-line
  • 1 1 个回答
  • 2861 Views

1 个回答

  • Voted
  1. Best Answer
    heemayl
    2015-12-20T20:46:51+08:002015-12-20T20:46:51+08:00

    您还没有关闭两个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

相关问题

  • 如何从命令行仅安装安全更新?关于如何管理更新的一些提示

  • 如何从命令行刻录双层 dvd iso

  • 如何从命令行判断机器是否需要重新启动?

  • 文件权限如何工作?文件权限用户和组

  • 如何在 Vim 中启用全彩支持?

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何运行 .sh 脚本?

    • 16 个回答
  • Marko Smith

    如何安装 .tar.gz(或 .tar.bz2)文件?

    • 14 个回答
  • Marko Smith

    如何列出所有已安装的软件包

    • 24 个回答
  • Marko Smith

    无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗?

    • 25 个回答
  • Martin Hope
    Flimm 如何在没有 sudo 的情况下使用 docker? 2014-06-07 00:17:43 +0800 CST
  • Martin Hope
    Ivan 如何列出所有已安装的软件包 2010-12-17 18:08:49 +0800 CST
  • Martin Hope
    La Ode Adam Saputra 无法锁定管理目录 (/var/lib/dpkg/) 是另一个进程在使用它吗? 2010-11-30 18:12:48 +0800 CST
  • Martin Hope
    David Barry 如何从命令行确定目录(文件夹)的总大小? 2010-08-06 10:20:23 +0800 CST
  • Martin Hope
    jfoucher “以下软件包已被保留:”为什么以及如何解决? 2010-08-01 13:59:22 +0800 CST
  • Martin Hope
    David Ashford 如何删除 PPA? 2010-07-30 01:09:42 +0800 CST

热门标签

10.10 10.04 gnome networking server command-line package-management software-recommendation sound xorg

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve