期末考试的shell script题

要求:

  1. 当前用户在字符界面下
  2. 进入用户的主目录
  3. 显示菜单,让用户选择,包括:1. 启动vi 2. 启动X Window 3.检查主目录下是否有.conf结尾的文件,如果有则使用at在23:00进行后台备份

 

> #!/bin/bash
> #author: kavinyao@gmail.com
> 
> #user=`whoami`
> #if [ $user = "root" ]
> #then
> #    home_dir="/root"
> #else
> #    home_dir="/home/$user"
> #fi
> #
> #cd $home_dir
> 
> cd ~
> 
> goodChoice=false
> until $goodChoice
> do
>     echo "what do you want to do? (enter number)"
>     echo "1. start vi"
>     echo "2. start x windows"
>     echo "3. backup *.conf"
> 
>     read option
> 
>     case $option in
>     "1")
>         goodChoice=true
>         vi;;
>     "2")
>         goodChoice=true
>         startx;;
>     "3")
>         goodChoice=true
>         
>         if [ -e *.conf ]
>         then
>             #echo "tar cvf backup.tar $home_dir/*.conf &" > job
>             echo "tar cvf backup.tar $HOME/*.conf &" > job
>             at -f job 23:00 
>             echo "back up set successfully"
>         else
>             echo "no *.conf found, will not backup"
>         fi
>         ;;
>     *)
>         echo "bad choice, please try again"
>     esac
> done