- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Help script MENU
Categories
Company
Local Language
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
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
Community
Resources
Forums
Blogs
- 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
тАО08-05-2008 05:05 AM
тАО08-05-2008 05:05 AM
I using select in my script, but i would like to include an exit or quit in a option in menu.
tput clear
export PATH=/usr/sbin:/usr/bin:/usr/contrib/bin:/opt/perl/bin:/opt/ignite/bin:
clear
# Diretorio das imagens
export CAM1=/var/opt/ignite/recovery/archives/PJHPXC01
export IGN_LOG=/home/ignite
echo
echo
echo
echo "Deseja verificar log de alguma imagem (y/n) ? \c"
read OPCAO
if [ "$OPCAO" = "y" -o "$OPCAO" = "Y" ]
then
PS3='Qual das imagens acima deseja ver o log? '
echo
select file in $(ls -tr $IGN_LOG | grep logimage)
do
echo $file
cat $IGN_LOG/$file | more
break
done
exit 0
echo "[ Enter ]"
read
echo
echo "Tecle [Enter] para voltar ao MENU"
read
else
if [ "$OPCAO" = "n" -o "$OPCAO" = "N" ]
then
echo
echo "[ Enter ]"
read
exit
else
echo "Opcao Invalida"
read
exit
fi
fi
clear
WAIT
Fernando.
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2008 05:32 AM
тАО08-05-2008 05:32 AM
Re: Help script MENU
I dislike the 'select' statement for menus for the problem you have. The 'select' parameter is set to null for non-matches leaving you limited control.
You could handle invalid selections as a "break":
#!/usr/bin/sh
select thing in A B C
do
echo "${thing} seen"
[ -z "${thing}" ] && { echo "BAD THING!"; break; }
done
echo "exiting"
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2008 05:39 AM
тАО08-05-2008 05:39 AM
Re: Help script MENU
I would suggest a different approach. You appear to be offering a list of files for viewing. You could build and display the list by writing the filenames, one per line, in a temporary file. Then 'cat -n' the temporary file for the user. This shows them a number and a filename.
Read the user's selection; validate that the number selected is in range and 'cat' the filename associated with the number selected as recorded in the temporary file.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-05-2008 10:24 PM
тАО08-05-2008 10:24 PM
SolutionWhy is this any better than select?
Fernando's select nicely gets the files and adds a number before each. It validates the number and either re-prompts or returns an empty string. (This is what's missing.)
>iI would like to include an exit or quit in a option in menu.
As JRF mentioned, you need to handle the empty string. If you want to add more options, you just fiddle with the pipeline:
... $(ls -tr $IGN_LOG | grep logimage; echo exit quit)
The user won't be able to type "exit" or "quit" but there will be a number for that option.
If you want to see what the the user typed, you can use something like:
select ident in $(ls p* ; echo exit quit); do
echo "Returned: $ident"
if [ "$ident" = "" ]; then
echo "Invalid: user typed: $REPLY"
break
fi
case $ident in
exit) exit ;;
quit) break 2 ;;
*) echo "other" ;;
esac
done
echo "After select"
- Tags:
- select
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2008 08:27 AM
тАО08-06-2008 08:27 AM
Re: Help script MENU
But when i choose other option, the output:
^ZM-\^A^C^L^B`^C$^B$^CM-T^B^D^BM-x^BM-D^B^T^DM-4^CM-`^D^L^DM-^H^DM-`^CM-8^CP^BH^D`^BM-^L^D8
^Ch^E^T^E^D^C4^CM-^@^CM-^\^Bt^BM-(^B8^^P^F.cshrc_^P^F.login`^.profilea^P^E.exrcb^X^L.profile.oldc
^T
adm_ignited^X^Lcreate_imagee^\^Pverifica_montadof^\^O.verifica_imageg ^S.verifica_image.oldh^.formatai^temp.txtj^X
.create_imagek^P^C^BM-d.swp^\^Q.verifica_montadoq^X^N.verifica_logs^AM-r^X^LPJHPXC01.tar^AM-q^\^Qignite_backup.tar^A
Z^\^Oformat.crontab.^A]^\^Qlogimage.crontab.^AM-.^L^A1^A\,^_logimage.crontab.20080803-02:24^A[,^_logimage.crontab.20080803-02:25
^A`(^]format.crontab.20080803-08:49^Aa(^]format.crontab.20080803-08:50^Ag,^_logimage.crontab.20080804-10:39^A^,^_logimage.crontab.2008
0804-10:40^AM-^U$^X.verifica_logs.05-8-2008^AM-^V^P^Dquit^AM-"^ZM-l^Dexit
My script changed:
tput clear
export PATH=/usr/sbin:/usr/bin:/usr/contrib/bin:/opt/perl/bin:/opt/ignite/bin:
clear
# Diretorio das imagens
export CAM1=/var/opt/ignite/recovery/archives/PJHPXC01
export IGN_LOG=/home/ignite
echo
echo
echo
echo "Deseja verificar log de alguma imagem (y/n) ? \c"
read OPCAO
if [ "$OPCAO" = "y" -o "$OPCAO" = "Y" ]
then
PS3='Qual das imagens acima deseja ver o log? '
file2=`ls -tr $IGN_LOG | grep logimage`
select ident in $(ls -tr $IGN_LOG | grep logimage; echo exit); do
#echo "Returned: `cat $IGN_LOG/$ident 2> /tmp/lixo.txt`" | more
cat $IGN_LOG/$ident 2> /tmp/lixo.txt | more
exit
if [ "$ident" = "" ]; then
echo "Opcao Invalida: $REPLY"
break
fi
case $ident in
exit) exit ;;
*) echo "other" ;;
esac
done
echo "Selecionar outra opcao"
echo "Tecle [Enter] para voltar ao MENU"
read
else
if [ "$OPCAO" = "n" -o "$OPCAO" = "N" ]
then
echo
echo "[ Enter ]"
read
exit
else
echo "Opcao Invalida"
read
exit
fi
fi
clear
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2008 09:19 AM
тАО08-06-2008 09:19 AM
Re: Help script MENU
As I originally said, "The 'select' parameter is set to null for non-matches leaving you limited control".
Now, Dennis offered a way to add the "quit" prompt by munging with the data in your pipe. Nice touch, Dennis.
But, as I said, non-matches leave you with an empty (undefined) argument. Thus when you do:
# cat $IGN_LOG/$ident 2> /tmp/lixo.txt | more
...and the value of 'ident' is empty, you are really reading the *directory* leading to garbage output!
Thus, at the least, move the check for an empty 'ident' ahead of the 'cat'.
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО08-06-2008 06:14 PM
тАО08-06-2008 06:14 PM
Re: Help script MENU
Right. As I mentioned, you can also check $REPLY for the actual invalid input.