LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (http://www.linuxquestions.org/questions/programming-9/)
-   -   Select menu to show after a process. (http://www.linuxquestions.org/questions/programming-9/select-menu-to-show-after-a-process-555925/)

bijit1709 05-22-2007 09:47 PM

Select menu to show after a process.
 
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?

makyo 05-24-2007 10:51 AM

Hi.

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

cheers, makyo

bijit1709 05-24-2007 12:26 PM

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.

makyo 05-24-2007 02:05 PM

Hi.
Quote:

Originally Posted by bijit1709
...
Is that understandable ...

No, but I'm sure someone will be along that understands what you require ... cheers, makyo

chrism01 05-25-2007 03:29 AM

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.

druuna 05-25-2007 03:43 AM

Hi,

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
$
Hope this helps.

bijit1709 05-25-2007 01:07 PM

I tried the code above but I still have to double hit enter so the display shows back, it doesn't appear the way you have it in the example.

Quote:

$ ./s1
1) Yes
2) No
DO YOU WISH TO LOAD THIS FILE? 1
Running programs.
DO YOU WISH TO LOAD THIS FILE?
1) Yes
2) No
DO YOU WISH TO LOAD THIS FILE? 2
$
Did you do something else?

druuna 05-25-2007 02:31 PM

Hi,

I just tried it on another box and it shows the same behavior as you have.

I've trying to figure out why and how to solve this and have been unsuccessful up to this point. I'll let you know if I figure it out.

bijit1709 05-25-2007 05:28 PM

Sure. I will be looking forward for your email with the solution. Meanwhile I will try some stuff too.

druuna 05-26-2007 05:43 AM

Hi,

Back again.

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

Hope this helps/clears things up a bit.

sixerjman 02-03-2013 04:36 PM

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.


All times are GMT -5. The time now is 09:22 AM.