|
|||||||
| Forums | Search Forums | Register | Forum Rules | Man Pages | Albums | FAQ | Members | Calendar | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here. |
|
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
Shell script menu
hi guys, how would you do the following? I have a menu with 5 options in my shell script:
1. Run function 1 against files 2. Run function 2 against files 3. Run function 3 against files 4. Run function 4 against files 5. Run function 5 against files I'd like to be able to run multiple functions however based on what the user inputs, for for example if I press key 1,2 and 4 then I want to run function 1, 2 and 4, if I press key 1 and 4 then only run function 1 and 4, if i just press key number 1 then i only want to run function 1 - any ideas? ![]() |
| Sponsored Links | ||
|
|
#2
|
||||
|
||||
|
Depends on how you wrote your menu script:
How do you capture the input? in sequence on in one go? What are these functions? should they be running at the same time or one after the other... |
| Sponsored Links | ||
|
|
#3
|
|||
|
|||
|
They can just run one after the other, it's just a read: Code:
read rSelection
if [[ $rSelection == '1' ]] then
#call function 1
else
if [[ $rSelection == '2' ]] then
#call function 2
else
if [[ $rSelection == '3' ]] then
#call function 3
else
if [[ $rSelection == '4' ]] then
#call function 4
else
if [[ $rSelection == '5' ]] then
#call function 5
else
echo "Exiting"
exit
fi
fiThat's what i have at the moment, too basic for what i need
|
|
#4
|
|||
|
|||
|
Try something like: Code:
f1 () {
echo running fn1
}
f2 () {
echo running fn2
}
f3 () {
echo running fn3
}
f4 () {
echo running fn4
}
echo "enter choice -- multiple choice can be provided separated by space"
read choice
set -- $choice
for i in $@
do
echo "run function $i"
f${i}
done |
| The Following User Says Thank You to clx For This Useful Post: | ||
rich@ardz (09-24-2010) | ||
| Sponsored Links | |
|
|
#5
|
||||
|
||||
|
What I see (but its friday...) is ONE read so all your values (or just one) are read in one go. One way to do things would be to stripe the entry ( what do you see when you enter 123? do you get 1 2 3 or 123? in other words is there a separator?) and use the values in a loop That would give you something like: Code:
for i in $rSelection (if there were a blank between the values) # but you could use while...
do
<Your if paragraph
fi >
done |
| The Following User Says Thank You to vbe For This Useful Post: | ||
clx (09-24-2010) | ||
| Sponsored Links | |
|
|
#6
|
|||
|
|||
|
That's a good point. Code:
for i in $choice
do
echo "run function $i"
f${i}
doneshould do the things. |
| The Following User Says Thank You to clx For This Useful Post: | ||
rich@ardz (09-24-2010) | ||
| Sponsored Links | |
|
|
#7
|
|||
|
|||
|
cheers guys, not really following though Code:
for i in $choice
do
echo "run function $i"
f${i}
donehow does that work if I hit the 1 and 2 key for example? ---------- Post updated at 02:14 PM ---------- Previous update was at 02:02 PM ---------- sorry I see now ![]() love it!
|
| Sponsored Links | ||
|
![]() |
| Thread Tools | Search this Thread |
| Display Modes | |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Write shell script using menu-driven approach to show various system | bboyjervis | SuSE | 1 | 06-06-2010 11:01 PM |
| Menu Driven Shell Script which accepts1 to 5 options | vaghya | Homework & Coursework Questions | 1 | 04-21-2010 07:19 AM |
| shell script to alter grub menu.lst | ppucci | Shell Programming and Scripting | 1 | 06-27-2009 07:10 PM |
| Unix Shell Script: With Menu Option | jroberson | Shell Programming and Scripting | 11 | 08-26-2008 06:04 PM |
| Changing korn shell script text Menu colors? | darthur | UNIX for Dummies Questions & Answers | 6 | 01-20-2002 06:15 PM |
|
|