LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 826|回复: 2

初学者求助:这个shell有啥问题啊??

[复制链接]
发表于 2007-7-16 21:06:23 | 显示全部楼层 |阅读模式
#退出程序函数
quit()
{
  clear
  echo "***************************************************"
  echo "**       Thank you for your use,Good bye!        **"
  echo "**         If you have some good advice,         **"
  echo "**       please contact me through email:        **"
  echo "**          personalbest123@126.com              **"
  echo "**       With your advice I'll do better!        **"
  exit 0
}
#欢迎函数
welcome()
{
  clear
  echo "***************************************************"
  echo "**       Welcome to this little program!         **"
  echo "**   It helps you to do something about files.   **"
  echo "**           Created by Gerrard                  **"
}  
#查看指定目录下文件函数
display()
{
  clear
  echo  "please input name of directory "
  read  MULU
  cd  $MULU
  ls –l
}
#将指定文件打包函数
gettar()
{
  clear
  echo "please input the name of the file to be ziped"
  read FILE
  gzip $FILE
  echo "File $FILE is ziped"
}
#将指定文件解压函数
unpack()
{
  clear
  UNPACK=1
  echo -e "lease input the filename to be unpacked:\c"
  read FILE
  echo "Unpacking,Please wait!..."
  if [ ${FILE##*.} = gz ] ; then
        TEMP=${FILE%.*}
        if [ ${TEMP##*.} = tar ] ; then
                tar zxvf $FILE
                UNPACK=$?
                echo "This is a tar.gz package"
        else
                gunzip $FILE
                UNPACK=$?
                echo "This is a gz package"
        fi
  fi

  if [ ${FILE##*.} = tar ] ; then
        tar xvf $FILE
        UNPACK=$?
        echo "This is a tar package"
  fi

  if [ $UNPACK = 0 ] ; then
        echo "Success!"
        cat $FILE
  else
        echo "Maybe it is not a package or the package is damaged?"
  fi
}
#删除指定文件函数
delete()
{
  clear
  echo -e "lease Enter the filename to be deleted:\c"
  read FILE
  echo "Deleting,Please wait!..."
  gzip $FILE //先对文件进行压缩
  mv $FILE.gz $HOME/dustbin //移动到回收站
  echo "File $FILE is deleted !"
}
#找出含有指定关键字的文件
findkey()
{
   while true;
   do
   echo "Input directory:"
   read dir
   if [ -e $dir ];then
   echo -n "Input keyword: "
   read "key"
   grep -R "$key" $dir 2>/dev/null|less
   else "The directory is not exist ! ";
   fi
   done
}

clear
while true
do
  echo "======================================================"
  echo "***          Fundenmental File Operation           ***"
  echo "             1-DISPLAY FILES IN DIRECTARY             "
  echo "             2-Pack A File                            "
  echo "             3-Unpack A File                          "
  echo "             4-Delete A File                          "
  echo "             5-Find A File Containing A Keyword       "
  echo "             0-EXIT                                   "
  echo "======================================================"
  echo -e "lease Enter a Choice(0--5):\c"
  read CHOICE
  case $CHOICE in
  1) display;;
  2) gettar;;
  3) unpack;;
  4) delete;;
  5) findkey;;
  0) quit;;
  *) echo "Invalid Choice!Correct Choice is (0--5)"
     sleep 4
     clear;;
   esac
  done
发表于 2007-7-17 09:33:24 | 显示全部楼层
有什么问题吗?
回复 支持 反对

使用道具 举报

发表于 2007-7-18 23:24:51 | 显示全部楼层
你说有啥问题?
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表