Results 1 to 2 of 2

Thread: Case Command Syntax Works in Unix, not Linux - Help!

  1. #1
    Junior Member
    Join Date
    Apr 2011
    Posts
    5
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default Case Command Syntax Works in Unix, not Linux - Help!

    I have a script that works well in Unix. The syntax is as follows:


    Code:
    menu_1 () {
    
        Command 1
        Command 2
    }
    
    menu_2 () {
        Command 1
        Command 2
    }
    
    while :
    do
    cat << !
    
    Please select:
    
    1. Menu 1
    2. Menu 2
    3. Quit
    
    !
    
    echo "Your choice? : "
    read choice
    
    case $choice in
    1) menu_1;;
    2) menu_2;;
    3) quit;;
    *) echo "\"$choice\" is not valid "; sleep 2;;
    esac
    done
    However, when I try to the case command in the same way under Linux, I get a series of syntax errors that reference either the closing } or any line that starts off with "Menu." Removing the case command and menu options from the script and it works fine. Can anyone help me or point me to a good tutorial that uses case in Linux for building a menu?

    Thank you kindly for your help.

    Pablo
    Last edited by pablo0713; 23rd August 2011 at 07:28 AM.

  2. #2
    Senior Member cfajohnson's Avatar
    Join Date
    May 2009
    Posts
    190
    Thanks
    0
    Thanked 44 Times in 36 Posts
    Rep Power
    10

    Default

    Quote Originally Posted by pablo0713 View Post
    I have a script that works well in Unix. The syntax is as follows:

    Code:
    menu_1 () {
        Command 1
        Command 2
    }
    
    menu_2 () {
        Command 1
        Command 2
    }
    
    while :
    do
    cat << !
    
    Please select:
    
    1. Menu 1
    2. Menu 2
    3. Quit
    
    !
    
    echo "Your choice? : "
    read choice
    
    case $choice in
    1) menu_1;;
    2) menu_2;;
    3) quit;;

    Code:
    3) exit ;;
    *) echo "\"$choice\" is not valid "; sleep 2;;
    esac
    done
    [/CODE]

    However, when I try to the case command in the same way under Linux, I get a series of syntax errors that reference either the closing } or any line that starts off with "Menu." Removing the case command and menu options from the script and it works fine. Can anyone help me or point me to a good tutorial that uses case in Linux for building a menu?

    That code works perfectly well in Linux. Are you sure you are using a Bourne-type shell (bash, dash, pdksh, ksh93).

    Try putting a shebang line at the top of your file:

    Code:
    #!/bin/sh

    Post the exact error mesages you get if you continue to have problems.
    Chris F.A. Johnson <http://cfajohnson.com/shell/>
    Shell programmer and author

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. HP-UX ps command syntax
    By chuikingman in forum HP-UX
    Replies: 4
    Last Post: 25th July 2011, 01:31 PM
  2. [Solved] Linux / UNIX find command -printf syntax to print filename
    By vapornoob in forum Shell scripting
    Replies: 3
    Last Post: 4th November 2010, 05:23 PM
  3. if csh false command syntax
    By chinalinix in forum Shell scripting
    Replies: 1
    Last Post: 10th March 2010, 05:11 PM
  4. how autosys works with crontab in unix
    By minalsilimkar in forum Solaris/OpenSolaris
    Replies: 0
    Last Post: 19th January 2009, 07:31 PM
  5. Replies: 2
    Last Post: 20th December 2008, 11:43 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •