Results 1 to 6 of 6
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 ...
- 08-18-2011 #1Just Joined!
- Join Date
- Aug 2011
- Posts
- 8
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 ... thanksLast edited by flyman; 08-18-2011 at 05:24 PM.
- 08-18-2011 #2Linux Guru
- Join Date
- May 2011
- Posts
- 1,842
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?
- 08-19-2011 #3Just Joined!
- Join Date
- Aug 2011
- Posts
- 8
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
- 08-19-2011 #4Linux Guru
- Join Date
- May 2011
- Posts
- 1,842
You can do this with case and read (both built-in bash functions). here's some pseudo-code to get you started:
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.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 doneLast edited by atreyu; 08-19-2011 at 05:18 PM. Reason: bash tips
- 08-19-2011 #5Just Joined!
- Join Date
- Aug 2011
- Posts
- 8
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:Smith
etroit:MI
Jim:Jones:Farmington Hills:MI
Jack:Frost
enver:CO
Sue:Apple:New York:NY
Cindy:Thompson:Battle Creek:MI
John:Smith
enver: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
- 08-19-2011 #6Linux Guru
- Join Date
- May 2011
- Posts
- 1,842
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...)


Reply With Quote