Find the answer to your Linux question:
Results 1 to 2 of 2
i created a piece of linux code but i'm having problems exiting it. Any advice about rectifying this is welcomed. options 1,2,3 work well. as well as the wildcard values, ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Feb 2008
    Posts
    1

    help needed to exit my code.


    i created a piece of linux code but i'm having problems exiting it. Any advice about rectifying this is welcomed. options 1,2,3 work well. as well as the wildcard values, however i can't get my exit option to work.

    #! /bin/sh

    echo "System Manager Version 1.0"
    echo "==========================================="
    echo "1. Show current user information"
    echo "2. Show most recent users"
    echo "3. Show current user"
    echo " "

    echo "Select an option from the menu above [1-3] or press Q to quit:"
    read input

    while [ $input != "1" ] || [ $input != "2" ] || [ $input != "3" ] || [ $input != "Q" ]

    do

    case "$input" in

    1)`clear`
    ./sysproginfo ;
    echo " "
    echo " "
    ./sysmgr ;

    ;;

    2)`clear`
    ./mrusers ;
    echo " "
    echo " "
    ./sysmgr ;

    ;;


    3)`clear`
    ./whoison ;
    echo " "
    echo " "
    ./sysmgr ;

    ;;

    *)`clear`
    echo "Wrong value entered"
    echo " "
    echo " "
    ./sysmgr;
    ;;


    Q)`clear`
    echo "Terminating program....GoodBye."
    exit;
    ;;

    esac
    done

  2. #2
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    A case statement will match the first option it can. In your case, the first option that a 'Q' matches is the * operator, and therefore, you never actually reach the 'Q' case.

    The '*' case should always be the last case, to avoid this very thing.

Posting Permissions

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