Operating System - HP-UX
1828921 Members
2839 Online
109986 Solutions
New Discussion

using "select var in " ??

 
SOLVED
Go to solution
rmueller58
Valued Contributor

using "select var in " ??

I am building a simple menu but would like to format screen paint it a bit better

Here is what it looks like when it's ran:

WST MAIN MENU
==============
1) wsfplus
2) wsfplustrain
3) wstplus
4) wstplustest
5) wstplustrain
Select DBNAME:


Here is the code set:



if [ "${GROUPNAME}" != "sysadmin" ]
then
DIST=`grep ${LOGNAME} /etc/passwd |awk -F":" '{print $6}'|cut -d"/" -f3`
TEST=`echo ${DIST} |cut -c 1-2`
export DN=`echo $DIST| awk '{print toupper($1)}'`
echo $DN MAIN MENU
echo ==============
PS3="Select DBNAME:"
select dbname in `grep ${TEST}[a-z]plus dbs.txt`
do
if [[ -n $dbname ]];
then
export SPIDBNAME=$dbname
echo SELECTED DB is $SPIDBNAME
echo fpsv43 -v4.3 -d$SPIDBNAME
break
else
echo "Invalid Selection"
echo " "
fi
done

else


It's not pretty but it woulds.

Would like to gussy it up a bit, center it or \t\t\t\t over all output.. Chose to use select rather then building a large set of case statements..

I am trying to build a consolidated menuing system for my users, based on groups, I've worked through the group logic, just not the screen formats..

Any suggestions appreciated.

7 REPLIES 7
rmueller58
Valued Contributor

Re: using "select var in " ??

would like it more like this:

WST MAIN MENU
==============
1) wsfplus
2) wsfplustrain
3) wstplus
4) wstplustest
5) wstplustrain

Select DBNAME:
rmueller58
Valued Contributor

Re: using "select var in " ??

oops

I would like every tabbed over 4 \t\t\t\t
rmueller58
Valued Contributor

Re: using "select var in " ??

I found a way to put the PS3 over


PS3=`echo '\t\t\t\t'` `echo SELECT DBNAME:"`


just not the select items..
James R. Ferguson
Acclaimed Contributor

Re: using "select var in " ??

Hi:

I'm not fond of 'select' menus from the standpoint of aesthetics. I don't think you can offset or center your menu. Consider this case where simple spaces are used to apparently offset things:

#!/usr/bin/sh
select DBNAME in " wsfplus" " wsfplustrain" \
" wstplus" " wstplustest" " wstplustrain"
do
echo "you selected: [${DBNAME}]"
done

...the problem is that the selection returns the word with its leading spaces too which is probably not what you want. I suppose you could then trim the leading spaces.

As an aside, I would change the use of shell backticks (for command substitution) to $(...). For example, instead of:

# TEST=`echo ${DIST}|cut -c 1-2`

...use:

# TEST=$(echo ${DIST}|cut -c 1-2)

This improves readability.

Regards!

...JRF...
rmueller58
Valued Contributor

Re: using "select var in " ??

Thanks James,

I agree the aesthetics of the select is awful.

I am considering trying to do something with awk to build a CASE from an array within the menu. looking for example, where I could take the information grabbed from my dbname.list file, grep for the "district" and display a district specific menu.

I did get the PS3 formatted, like you I don't like the formatting.

Thanks I will take a look at re-vamping things with a CASE..
James R. Ferguson
Acclaimed Contributor
Solution

Re: using "select var in " ??

Hi (again):

> ...where I could take the information grabbed from my dbname.list file, grep for the "district" and display a district specific menu.

You might consider sourcing (reading) separate files that describe the requisite menu options along with the valid triggers for each. Your 'case' statement would invoke the appropriate file to source.

Regards!

...JRF...
rmueller58
Valued Contributor

Re: using "select var in " ??

Thanks for the suggestion about the back ticks. old habits die hard..