LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 05-22-2007, 08:47 PM   #1
bijit1709
Member
 
Registered: Oct 2006
Location: Costa Rica, Escazu
Distribution: Slackware 12.0 (2.6.21.5)
Posts: 67

Rep: Reputation: 15
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?
 
Old 05-24-2007, 09:51 AM   #2
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
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
 
Old 05-24-2007, 11:26 AM   #3
bijit1709
Member
 
Registered: Oct 2006
Location: Costa Rica, Escazu
Distribution: Slackware 12.0 (2.6.21.5)
Posts: 67

Original Poster
Rep: Reputation: 15
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.
 
Old 05-24-2007, 01:05 PM   #4
makyo
Member
 
Registered: Aug 2006
Location: Saint Paul, MN, USA
Distribution: {Free,Open}BSD, CentOS, Debian, Fedora, Solaris, SuSE
Posts: 718

Rep: Reputation: 72
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
 
Old 05-25-2007, 02:29 AM   #5
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.5, Centos 5.10
Posts: 16,246

Rep: Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025Reputation: 2025
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.
 
Old 05-25-2007, 02:43 AM   #6
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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.
 
Old 05-25-2007, 12:07 PM   #7
bijit1709
Member
 
Registered: Oct 2006
Location: Costa Rica, Escazu
Distribution: Slackware 12.0 (2.6.21.5)
Posts: 67

Original Poster
Rep: Reputation: 15
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?
 
Old 05-25-2007, 01:31 PM   #8
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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.
 
Old 05-25-2007, 04:28 PM   #9
bijit1709
Member
 
Registered: Oct 2006
Location: Costa Rica, Escazu
Distribution: Slackware 12.0 (2.6.21.5)
Posts: 67

Original Poster
Rep: Reputation: 15
Sure. I will be looking forward for your email with the solution. Meanwhile I will try some stuff too.
 
Old 05-26-2007, 04:43 AM   #10
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371Reputation: 2371
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.
 
Old 02-03-2013, 03:36 PM   #11
sixerjman
Member
 
Registered: Sep 2004
Distribution: Debian Tesing / Unstable
Posts: 166
Blog Entries: 1

Rep: Reputation: 30
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.

Last edited by sixerjman; 02-03-2013 at 03:45 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
full screen menu to select games? johnson_steve Linux - Software 4 02-02-2006 06:43 AM
DVD menu - doesn't work/can't select anything pingu Linux - Software 3 10-31-2005 09:33 AM
making select show its menu in a bash script? zidane_tribal Programming 6 05-02-2005 05:52 AM
Select boot options in shutdown menu? dominik81 Mandriva 7 02-21-2004 03:21 AM
how to get the select menu k_ravindra_babu Linux - Newbie 1 01-04-2004 05:35 AM


All times are GMT -5. The time now is 04:17 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration