Linux Shell脚本 - 备份/还原

时间:2011-11-23 11:35:12

标签: linux shell

Stackoverflow的社区,

我在使用我正在设计的shell脚本时遇到问题......

#!/bin/sh
while :
do
clear
echo "-----------------------------
-----------"
echo "***************Main Menu****************"
echo "----------------------------------------"
echo "1. Backup Word Document"
echo "2. Backup Spreadsheet"
echo "3. Backup Picture"
echo "4. Restore Word Documents"
echo "5. Restore Spreadsheet"
echo "6. Restore Picture"
echo "7. EXIT"

echo "----------------------------------------"
pause
echo -n "Enter your menu choice [1-7]:"
read yourch
case $yourch in
1) echo ; tar -cvf /Files/*.doc /WP/ ; read ;;

1) echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

2) echo ; tar -cvf /Files/*.xls /EXCEL/ ; read ;;

2) echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

3) echo ; tar -cvf /Files/*.jpg /PICS/ ; read ;;

3) echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

4) echo ; tar xvzf /WP/*.doc ; read ;;
5) echo ; tar xvzf /EXCEL/*.xls ; read ;;
6) echo ; tar xvzf /PICS/*.jpg ; read ;;
7) exit 0 ;;

*) echo "Please press a number between 1 to 7";

错误显示'cript:第21行:意外令牌附近的语法错误'                  'cript:第21行:'case $ yourch

有没有人知道怎么通过这个错误?基本上我试图做的是能够备份文件名为“.doc”的一组文件并将它们放在备份文件夹中。然后,我可以将此文件夹中的文件还原到另一个文件夹。

亲切的问候,

1 个答案:

答案 0 :(得分:1)

我认为你遗漏了esacdone声明。

确定。使用这个:

#!/bin/sh
while :
do
  clear
  echo "-----------------------------
  -----------"
  echo "***************Main Menu****************"
  echo "----------------------------------------"
  echo "1. Backup Word Document"
  echo "2. Backup Spreadsheet"
  echo "3. Backup Picture"
  echo "4. Restore Word Documents"
  echo "5. Restore Spreadsheet"
  echo "6. Restore Picture"
  echo "7. EXIT"

  echo "----------------------------------------"

  echo -n "Enter your menu choice [1-7]:"
  read yourch
  case $yourch in
      1) echo ; 
     tar -cvf /Files/*.doc /WP/ ; read ;
     echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

      2)  echo ; tar -cvf /Files/*.xls /EXCEL/ ; read ;
      echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

      3) echo ; tar -cvf /Files/*.jpg /PICS/ ; read ;
     echo "Today is";  date +%Y%m%d-%H:%M 2>&1 ; echo "Press a key..." ; read ;;

      4) echo ; tar xvzf /WP/*.doc ; read ;;
      5) echo ; tar xvzf /EXCEL/*.xls ; read ;;
      6) echo ; tar xvzf /PICS/*.jpg ; read ;;
      7) exit 0 ;;

  *) echo "Please press a number between 1 to 7";;

  esac
done