Something is wrong with this switch( case statement.


Login or Register to Reply

 
Thread Tools Search this Thread
# 1  
Old 11-06-2010
Question Something is wrong with this switch( case statement.

I started writing a script to save the files from a camera I got the other day, which mounts in /Volumes , and I got into it and started building this menu. The only problem is that the switch case is coming up as a syntax error at the parenthesis after a case. Here is the code:
Code:
while :
 do
    clear
    echo "-----Menu for Camera Save Script-----"
    echo " Main Menu "
    echo "-------------------------------------"
    echo "[1] Save to dir: Todays date/time"
    echo "[2] Save files custom dir: "
    echo "[5] Exit/Stop"
    echo "======================="
    echo -n "Enter your menu choice [1,2,5]: "
    read yourch
    case "$yourch" in
      1)
        mkdir $HOME/Pictures/`date +%d_%m_%H%M`;
        mv /Volumes/SpyCam/_REC/100MEDIA/* $HOME/Pictures/`date +%d_%m_%H%M`;
        ;;
      2)
	echo "Enter Name of New Dir: ";
        read `newdir`;
        mkdir $HOME/Pictures/$newdir;
        mv /Volumes/SpyCam/_REC/100MEDIA/* $HOME/Pictures/$newdir;
        ;;
      5)
        exit 0;
        ;;
      *)
        echo "No try 1, 2 or 5.";
        echo "Press a key. . .";
        read;
        ;;
  esac
done

As you can see, it displays the menu, and once it does that, it waits for two options, one for an auto named directory with the date and time, or one for a custom named directory. It won't work though. it says there is an unexpected parentheses at 1).
Thanks for anyone who tries to figure this out.
oh, also, I am executing within bash.

Last edited by Franklin52; 11-06-2010 at 08:13 AM.. Reason: Please use code tags
# 2  
Old 11-06-2010
Hi.

I have seen errors like this when a script has been edited with DOS-style newlines. However, I cannot duplicate your results exactly.

Have you edited this file on Windows or something similar? ... cheers, drl

Last edited by drl; 11-06-2010 at 12:52 PM..
# 3  
Old 11-06-2010
Text editor

No, I used nano, although I did copy and paste some of it into TextEdit before moving it back along.
here is the actual error message:
/bin/cammenu: line 14: syntax error near unexpected token `)'
/bin/cammenu: line 14: ` 1)'

---------- Post updated at 01:35 PM ---------- Previous update was at 01:01 PM ----------

alright. I redid all of the spacing and finally managed to get it to work. here it is fixed...
I am still making other modifications, but the case thing works now. thanks for the idea.
code:
Code:
#!/bin/bash
while :
do
echo "-----Menu for Camera Save Script-----"
echo " Main Menu "
echo "-------------------------------------"
echo "[1] Save to dir: Todays date/time"
echo "[2] Save files custom dir: "
echo "[5] Exit/Stop"
echo "======================="
echo -n "Enter your menu choice [1,2,5]: "
read yourch
  case "$yourch" in
1)
    mkdir $HOME/Pictures/`date +%d_%m_%H%M`
    mv /Volumes/SpyCam/_REC/100MEDIA/* $HOME/Pictures/`date +%d_%m_%H%M`
    ;;
2)
    echo "Enter Name of New Dir: "
    read `newdir`
    mkdir $HOME/Pictures/$newdir/
    mv /Volumes/SpyCam/_REC/100MEDIA/* $HOME/Pictures/$newdir/
    ;;
5)
    exit 0
    ;;
*)
    echo "No try 1, 2 or 5."
    echo "Press a key. . ."                                                      
    read
    ;;
  esac
done


Last edited by snakemasterAK; 11-06-2010 at 06:41 PM.. Reason: I found the Code tag...
Login or Register to Reply

|
Thread Tools Search this Thread
Search this Thread:
Advanced Search

More UNIX and Linux Forum Topics You Might Find Helpful
Wrong case behaviour? elbrand Shell Programming and Scripting 7 3 Weeks Ago 12:19 PM
Missing Logic Looping Through Switch Statement Azrael Programming 6 09-03-2018 04:54 AM
Why does it not work (Switch Case)? JustAnUser Shell Programming and Scripting 6 03-05-2015 11:31 AM
Passing arguments from command line to switch case statement in C Priya Amaresh Programming 2 05-02-2013 02:35 AM
Why result is wrong here ? whether break statement is wrong ? Akshay Hegde Shell Programming and Scripting 2 03-11-2013 12:31 AM
What's wrong with the do statement? ramneim Shell Programming and Scripting 7 08-28-2012 07:43 AM
Error while executing switch case for find and replace specific file. Help Me... lathigara Shell Programming and Scripting 4 07-30-2012 07:32 AM
Switch Case not working Rapcher Shell Programming and Scripting 1 03-29-2012 12:46 AM
Example of switch case in Bash sumit the cool Shell Programming and Scripting 1 01-31-2010 02:48 PM
Tcl switch statement SFNYC Shell Programming and Scripting 2 05-17-2009 08:15 AM
Help needed in Switch Case spkandy Shell Programming and Scripting 2 12-10-2008 03:20 PM
Comapilation error with Switch statement jagan_kalluri Programming 1 11-20-2008 05:38 AM
Help needed in switch case handling in UNIX Balamani Shell Programming and Scripting 1 07-03-2008 03:46 AM
Ignore case sensitive in Case Switch annelisa Shell Programming and Scripting 1 07-13-2006 05:36 AM
using getopt with a switch statement gammarays Shell Programming and Scripting 6 02-09-2005 02:03 AM