ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Does anyone know how to make a select menu show after the process in it done?
eg:
PS3='DO YOU WISH TO LOAD THIS FILE? '
select opt in Yes No; do
case $opt in
Yes )
runupd 20$days
after 20$days;;
No ) exit;;
* ) echo "Please select from an option above!";;
esac
done
After this is done only the PS3 will be displayed. How do I do so after it is done The Whole menu is shown back again and i don't have to press enter twice so it is shown?
If I understand your question correctly, wrapping the select in an infinite loop may help:
Code:
#!/bin/sh
# @(#) s1 Demonstrate re-display of menu.
PS3='DO YOU WISH TO LOAD THIS FILE? '
while :
do
select opt in Yes No
do
case $opt in
Yes )
echo runupd 20$days
echo after 20$days;;
No ) exit;;
* ) echo "Please select from an option number:"
break ;;
esac
done
done
exit 0
Well what that does is not what exactly what I am looking for. I want:
Code:
1) Yes
2) No
DO YOU WISH TO LOAD THIS FILE?
After I select lets say 1 and the process for one is done. When I get back to the menu its displays as above not as below. Because when when I get the display as below I have to hit enter twice so the menu appears..
Code:
DO YOU WISH TO LOAD THIS FILE?
Is that understandable or do you need anything else for me to explain.
Yeah, i've done it a long time ago, but can't seem to find an example now.
Basically, assume a text style front end to a list of choices which do 'something'.
After a given choice completes, auto-redisplay the entire menu again.
The code works as you want. The 'only' difference being that I used and echo and not the actual runupd and after commands (don't know them).
Could it be that those programs interfere with the rest of the script?
What happens if you substitute the following parts:
runupd 20$days
after 20$days;;
into:
echo "running runupd and after";;
Example code:
Code:
#!/bin/bash
PS3='DO YOU WISH TO LOAD THIS FILE? '
select opt in Yes No
do
case $opt in
Yes ) echo "Running programs.";;
No ) exit;;
* ) echo "Please select from an option above!";;
esac
done
Test run:
Quote:
$ ./s1.sh
1) Yes
2) No
DO YOU WISH TO LOAD THIS FILE? 1
Running programs.
1) Yes
2) No
DO YOU WISH TO LOAD THIS FILE? 2
$
On linux boxes this is correct behavior. The PS3 prompt and the LIST are only shown when the input is empty, otherwise only the PS3 prompt is shown.
I'll have to try and figure out why this differs on a none linux box (a SUN box in this case). SUN probably patched bash to change this behavior. I do believe that installing a 'normal' gnu bash on a SUN box will show the same behavior as on linux (LIST is only shown once).
Here's a different way to solve your problem:
Code:
#!/bin/bash
clear
while :
do
echo ''
echo 'DO YOU WISH TO LOAD THIS FILE? '
echo '1) Yes'
echo '2) No'
echo ''
echo -n 'Please enter your choice : '
read ANSWER
case $ANSWER in
"1" | "Yes" ) echo "Running programs."
break;;
"2" | "No" ) exit 0;;
* ) echo "Please select from an option above!"
esac
done
Most assuredly this is not a timely answer but I had the same problem today and found a solution thanks to druuna's last post re: the menu is
not displayed unless the 'line read' value is null. Hopefully this provides a little time saver for someone else.
From the bash 'help select':
If the line is empty, WORDS and the prompt are
redisplayed. If EOF is read, the command completes. Any other
value read causes NAME to be set to null. The line read is saved
in the variable REPLY.
Pressing enter after the PS3 prompt is displayed nulls out the line read
and causes the menu to be redisplayed. The same effect is attained
by setting REPLY to null (REPLY='') at the bottom of the while loop.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.