- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- setting read from a list of options
Operating System - HP-UX
1753699
Members
4924
Online
108799
Solutions
Forums
Categories
Company
Local Language
юдл
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Forums
Discussions
юдл
back
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2009 06:18 AM
тАО06-06-2009 06:18 AM
I am attempting to create a menu that will wait for input and I want to be able to check that input is valid before the script can continue:
here is the code to display the options:
set -A CLUST ECM SIG
echo "\n\n`${BOLD}` Please select a Cluster to configure : -\n `${ENVIROCOL}`"
read ANS
cnt=1
for CLUSID in `echo ${CLUST[*]}`
do
print "\t\t${cnt})\t${CLUSID}\n"
[[ $cnt -eq ${#CLUST[*]} ]] && print "\t\tA)\tAll Clusters\n\n\t\tX)\tExit menu\n"
(( cnt +=1 ))
done
1) ECM
2) SIG
A) All Clusters
X) Exit menu
there could be up to 20 clusters but in this example there is only two.
I now need to check that the option is valid ie
1 = ECM
2 = SIG
A = ALL
X = exit
I think I need to use
while read INP
do
if [[ ??
then not sure of the regex or is there a better way to read from the input ??
Thanks for any help
:-)
here is the code to display the options:
set -A CLUST ECM SIG
echo "\n\n`${BOLD}` Please select a Cluster to configure : -\n `${ENVIROCOL}`"
read ANS
cnt=1
for CLUSID in `echo ${CLUST[*]}`
do
print "\t\t${cnt})\t${CLUSID}\n"
[[ $cnt -eq ${#CLUST[*]} ]] && print "\t\tA)\tAll Clusters\n\n\t\tX)\tExit menu\n"
(( cnt +=1 ))
done
1) ECM
2) SIG
A) All Clusters
X) Exit menu
there could be up to 20 clusters but in this example there is only two.
I now need to check that the option is valid ie
1 = ECM
2 = SIG
A = ALL
X = exit
I think I need to use
while read INP
do
if [[ ??
then not sure of the regex or is there a better way to read from the input ??
Thanks for any help
:-)
hello
Solved! Go to Solution.
3 REPLIES 3
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2009 06:35 AM
тАО06-06-2009 06:35 AM
Solution
You could use the select command to put up a menu with numbers and your strings. It returns that string or an error indicator.
Or you could use a case to parse the string. Or if small, you could use if with pattern matching.
In your case you could just use:
select INP in ${CLUST[*]} A X; do
case INP in
A) do_all;;
X) do_exit;;
*) do matching for each CLUST;;
esac
done
>for CLUSID in `echo ${CLUST[*]}`
You don't need that echo:
for CLUSID in ${CLUST[*]}
Or you could use a case to parse the string. Or if small, you could use if with pattern matching.
In your case you could just use:
select INP in ${CLUST[*]} A X; do
case INP in
A) do_all;;
X) do_exit;;
*) do matching for each CLUST;;
esac
done
>for CLUSID in `echo ${CLUST[*]}`
You don't need that echo:
for CLUSID in ${CLUST[*]}
- Tags:
- select
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-06-2009 10:16 AM
тАО06-06-2009 10:16 AM
Re: setting read from a list of options
Hi Chris:
I like to wrap things in a 'while true' loop like this:
#!/usr/bin/sh
while true
do
clear
tput smso
echo "Host: $(hostname). $(date "+%a %x %X %Z"). [ Cluster Selection Utility ]"
tput rmso
echo "\n>>> Enter < 0 > to Exit"
echo "\n>>> Enter < l > = ECM"
echo "\n>>> Enter < 2 > = SIG"
echo "\n>>> Enter < A > = All"
echo "\n--> \c"
read CHOICE
case ${CHOICE} in
0 ) clear
exit 0
;;
1 ) ${HOME}/thing1
;;
2 ) ${HOME}/thing2
;;
A ) ${HOME}/all
;;
"") continue
;;
* )
echo "\nInvalid selection; press return to continue \c"
read BITBUCKET
;;
esac
done
...
To exit the loop and continue the encapsulating script, a 'break' statement. Otherwise after running a selected event, simply 'exit' to end the script.
Regards!
...JRF...
I like to wrap things in a 'while true' loop like this:
#!/usr/bin/sh
while true
do
clear
tput smso
echo "Host: $(hostname). $(date "+%a %x %X %Z"). [ Cluster Selection Utility ]"
tput rmso
echo "\n>>> Enter < 0 > to Exit"
echo "\n>>> Enter < l > = ECM"
echo "\n>>> Enter < 2 > = SIG"
echo "\n>>> Enter < A > = All"
echo "\n--> \c"
read CHOICE
case ${CHOICE} in
0 ) clear
exit 0
;;
1 ) ${HOME}/thing1
;;
2 ) ${HOME}/thing2
;;
A ) ${HOME}/all
;;
"") continue
;;
* )
echo "\nInvalid selection; press return to continue \c"
read BITBUCKET
;;
esac
done
...
To exit the loop and continue the encapsulating script, a 'break' statement. Otherwise after running a selected event, simply 'exit' to end the script.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО06-08-2009 12:55 AM
тАО06-08-2009 12:55 AM
Re: setting read from a list of options
thanks guys,
Chris
Chris
hello
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP