Find the answer to your Linux question:
Results 1 to 6 of 6
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    struggling and need some help


    hey hows everyone ....

    ok I'm having hard times solving this problem ... I got a file continue a list of last names, first names, and address ... I wanna create a menu with or without using the tput command to display the following

    L - Print Last Names
    *********************** F - Print First Names
    *********************** C - Print First Name, Last Name sorted by city
    *********************** S - Print First Name, Last Name, State sorted by state
    *********************** Q - Exit the program

    does anyone know how to finish it plzz ... thanks
    Last edited by flyman; 08-18-2011 at 05:24 PM.

  2. #2
    What does your text file, the one containing last names, addresses, etc., look like (i.e., is it comma-delimited or what)?

    What have you tried so far? Can you PYC?

  3. #3
    my file looks like this
    last name: first name: street: city: zip-code

    the problem is I'm not really familiar with the menu format

  4. $spacer_open
    $spacer_close
  5. #4
    You can do this with case and read (both built-in bash functions). here's some pseudo-code to get you started:
    Code:
    func(){
      arg=$1
      echo "Do something with $arg, like look in your text file"
    }
    echo "Choices are:
    A) does x...
    B) does y...
    C) does z...
    "
    until [ -n "$choice" ]; do
      read -p "enter a choice: " choice
      case $choice in
        A)  func A;;
        B)  func B;;
        C)  func C;;
        *) echo "invalid choice  $choice - try again" 
        unset choice
      esac
    done
    EDIT: read up on bash functions with the command "man bash", and take a look at the bash scripts in /etc/init.d/ for usage examples.
    Last edited by atreyu; 08-19-2011 at 05:18 PM. Reason: bash tips

  6. #5
    thats the whole project.... and thats how I got so far but I'm having problem because it doesn't run when execute

    Please type the following information into a file of your choice:
    Stan:Smithetroit:MI
    Jim:Jones:Farmington Hills:MI
    Jack:Frostenver:CO
    Sue:Apple:New York:NY
    Cindy:Thompson:Battle Creek:MI
    John:Smithenver:CO
    George:Jones:New York:NY
    Then create a shell script (similar to Page 333 Project 6-1. This script will display the following information in a menu format:
    *********************** L - Print Last Names
    *********************** F - Print First Names
    *********************** C - Print First Name, Last Name sorted by city
    *********************** S - Print First Name, Last Name, State sorted by state
    *********************** Q - Exit the program
    ==================================


    information=~/source/customers
    loop=y
    while [ "$loop" = y ]
    do
    clear
    tput cup 3 12; echo "Customers Information"
    tput cup 4 12; echo "========================="
    tput cup 6 9; echo "L - Print Last Names"
    tput cup 7 9; echo "F - Print First Names"
    tput cup 8 9; echo "C - Print Last Name sorted by city"
    tput cup 9 9; echo "S - Print First Name, Last Name, State sorted by state"
    tput cup 10 9; echo "Q - Exit the program"

    read choice || continue
    case $choice in
    [Ll]) ./ customers;;
    [Ff]) ./customers ;;
    [Cc]) ./customers;;
    [Ss]) ./customers ;;
    [Qq]) exit ;;
    *) tput cup 14 4; echo "Invalid Code"; read choice ;;
    esac
    done

  7. #6
    What doesn't run when you execute?

    I see that in all your cases, it calls an external script, "./customers". Does that script exist in the current working directory, and is it executable? Even if it is, you are not telling it which case called it, so you should pass the arg to it from the case statement, e.g.:
    ./customers $choice

    Then in your ./customers script, have
    arg=$1
    echo "do something with $arg"

    (this thread seems familiar to me...)

Posting Permissions

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