1

Hi Community of Stackoverflow,

I am facing a problem here with my shell script that I am designing...

#!/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";

A error displays 'cript: line 21: syntax error near unexpected token 'in 'cript: line 21: 'case $yourch

Does anyone know how to by pass this error? Basically what im trying to do is be able to back up a set of files with the file name ".doc" and place them in a backup folder. I can then restore the files from this folder to another folder.

Kind Regards,

Ben

5
  • @KiranChandrashekhar I have added esac to the bottom of the script but it won't go past line 21. Commented Nov 23, 2011 at 11:40
  • This code is wrong, You cannot use multiple case statements Commented Nov 23, 2011 at 12:18
  • @KiranChandrashekhar Yes I have just found out that there are syntax errors within the statements, but I don't know exactly where. Could you point me in the right direction? Commented Nov 23, 2011 at 12:28
  • I just gave the working code for you. Are you still facing problem ? Commented Nov 23, 2011 at 12:38
  • I have typed it what you put and its now going back to line 21 "Syntax error near unexpected token 'in " – Commented Nov 23, 2011 at 12:40

1 Answer 1

1

I think you are missing esac and done statement.

Ok. Use this one :

#!/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
Sign up to request clarification or add additional context in comments.

9 Comments

Where should these be placed, I tried adding esac, does it need to be combined with done?
esac is to end the case statement and done is to end the do-while loop. As I see it, you need to put it at the end of the code (esac first) :)
I have put esac under *) echo "Please press a number between 1 to 7"); I have also added "Done" right under it. but it still shows the same error
Well, Here is my understanding: YOu cannot have two case statements 1) and 1). Combine all the statements under 1) and 2) and remove pause statement and use sleep command instead. I hope it works
Hi Kiran, I have added in "Sleep 1" instead of the pause statement. I have also removed the "Echo Todays Date" statements for the time being. It is still getting stuck at line 21 though :(
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.