我敢打赌我错过了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
您还没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