Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Automatic List of entries to choose from 1

Status
Not open for further replies.

TSch

Technical User
Jul 12, 2001
557
DE
Hi folks,

I'm using an array (set -A) to store a list of all available LPARs using certain HMC. Note: The number of entries in this array keeps changing as we're "constantly" adding and removing LPARs from the HMC.

Let's say the array content looks something like this:

Code:
Machine_A
Machine_B
Machine_C
Machine_D
Machine_E

Now what I'd like to accomplish is the following:
Read the array and create an output like this:

Code:
1) Machine_A    |    2) Machine_B    |    3) Machine_C
4) Machine_D    |    5) Machine_E

Please make a choice:

So he's supposed to automatically generate automatically increasing leading numbers (Sorry for my english, hope you know what I want so say !).

AND it's supposed to be possible to enter 1, 2, 3, 4 or 5 in order to run commands using the specified entry as a variable.

e.G.

Code:
command Machine_A

... after entering the "1"

Another important point is that the above output is NOT supposed to look like this:

Code:
1) Machine_A
2) Machine_B
3) Machine_C
...

There are supposed to appear up to 3 entries in every line ...

Any idea how this could be accomplished ?

Regards
Thomas
 
in korn shell: select statement

[tt]
set -A lpars -- ${list_of_lpars} # use some HMC magic to get list of LPARs ;-)
PS3="Select an LPAR (ctrl-D to exit) >"
select choice in ${lpars[*]}
do
echo choice is ${choice}
...
done[/tt]


HTH,

p5wizard
 
Perfect !
Thanks a lot ! :)
 
Hi

p5wizard said:
in korn shell: select statement
TSch said:
Perfect !
I believed that vertical listing is "NOT" acceptable for you...

Anyway, for a horizontal listing you have to print them out "manually" :
Bash:
[navy]lpar[/navy][teal]=([/teal] Machine_A Machine_B Machine_C Machine_D Machine_E [teal])[/teal]
[b]for[/b] [teal](([/teal][navy]i[/navy][teal]=[/teal][purple]0[/purple][teal],[/teal][navy]l[/navy][teal]=[/teal][navy]${#lpar[@]}[/navy][teal];[/teal]i[teal]<[/teal]l[teal];[/teal]i[teal]++));[/teal] [b]do[/b]
  [COLOR=chocolate]printf[/color] [green][i]'%2d) %-10s'[/i][/green] [navy]$([/navy][teal]([/teal] i[teal]+[/teal][purple]1[/purple] [teal]))[/teal] [green][i]"${lpar[i]}"[/i][/green]
  [teal](([/teal] i[teal]%[/teal][purple]3[/purple][teal]==[/teal][purple]2[/purple] [teal]))[/teal] [teal]&&[/teal] echo [teal]||[/teal] echo -n [green][i]'   |   '[/i][/green]
[b]done[/b]
[teal](([/teal] i[teal]%[/teal][purple]3[/purple] [teal]))[/teal] [teal]&&[/teal] echo

[COLOR=chocolate]read[/color] -p [green][i]'Please make a choice: '[/i][/green] choice
[teal](([/teal] choice[teal]>[/teal][purple]0[/purple] [teal]&&[/teal] choice[teal]<=[/teal]l [teal]))[/teal] [teal]&&[/teal] echo [green][i]"command ${lpar[choice-1]}"[/i][/green] [teal]||[/teal] echo [green][i]'Bad choice'[/i][/green]
Tested with Bash. The C-like [tt]for[/tt] will not work in Ksh. But as you specified no shell, I suppose Bash is also good for you.


Feherke.
 
@feherke: You're right of course. My mistake :)

Thanks a lot !
 
@feherke

If it is a very long list, select will print the items in multi-columnar format.

@Tsch

Try it, maybe you'll like it?



HTH,

p5wizard
 
[tt]

select choice in ${lpars[*]}
do
echo choice is ${choice}
done
1) one 16) five 31) one 46) five 61) six 76) seven
2) two 17) six 32) two 47) six 62) seven 77) one
3) three 18) seven 33) three 48) seven 63) one 78) two
4) four 19) one 34) four 49) one 64) two 79) three
5) five 20) two 35) one 50) two 65) three 80) four
6) six 21) three 36) two 51) three 66) four 81) five
7) one 22) four 37) three 52) four 67) five 82) six
8) two 23) one 38) four 53) five 68) six 83) seven
9) three 24) two 39) five 54) six 69) seven 84) one
10) four 25) three 40) six 55) seven 70) one 85) two
11) five 26) four 41) seven 56) one 71) two 86) three
12) one 27) five 42) one 57) two 72) three 87) four
13) two 28) one 43) two 58) three 73) four 88) five
14) three 29) two 44) three 59) four 74) five 89) six
15) four 30) three 45) four 60) five 75) six 90) seven
Select LPAR (ctrl-D to exit) >5
choice is five
Select LPAR (ctrl-D to exit) >58
choice is three
Select LPAR (ctrl-D to exit) >45
choice is four
Select LPAR (ctrl-D to exit) >99
choice is
Select LPAR (ctrl-D to exit) > [red][ENTER][/red]
1) one 16) five 31) one 46) five 61) six 76) seven
2) two 17) six 32) two 47) six 62) seven 77) one
3) three 18) seven 33) three 48) seven 63) one 78) two
4) four 19) one 34) four 49) one 64) two 79) three
5) five 20) two 35) one 50) two 65) three 80) four
6) six 21) three 36) two 51) three 66) four 81) five
7) one 22) four 37) three 52) four 67) five 82) six
8) two 23) one 38) four 53) five 68) six 83) seven
9) three 24) two 39) five 54) six 69) seven 84) one
10) four 25) three 40) six 55) seven 70) one 85) two
11) five 26) four 41) seven 56) one 71) two 86) three
12) one 27) five 42) one 57) two 72) three 87) four
13) two 28) one 43) two 58) three 73) four 88) five
14) three 29) two 44) three 59) four 74) five 89) six
15) four 30) three 45) four 60) five 75) six 90) seven
Select LPAR (ctrl-D to exit) > [red]ctl-D[/red][/tt]

Just pressing enter refreshes the list
ctrl-D finishes the loop
a number chooses the corresponding word in the list
some error checking needs to be written

But you'd need to have an extremely long list to use up even a 24x80 screen...



HTH,

p5wizard
 
Hi

p5wizard said:
@feherke

If it is a very long list, select will print the items in multi-columnar format.
I know it. I used it. I do not like it.

Usually I have the items in ascending order and finding a value is easier if they are enumerated as in our writing system : in lines, from left to right.


Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top