Format of 'select' generated menu


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Format of 'select' generated menu
# 1  
Old 04-11-2014
Format of 'select' generated menu

Oracle Linux 5.6 64-bit

Given the below snippet

Code:
ORACLE_SID=''
PS3='Select target (test) database being refreshed: '
#
while [[ $ORACLE_SID = "" ]]; do
  select ORACLE_SID in `egrep -i '^FS|^HR' /etc/oratab |\
      awk -F\: '{print $1}'|sort` ; do
    if [[ $ORACLE_SID = "" ]]; then
         echo
         echo "Please enter a valid number.  Retry.";
         echo
    elif [[ $ORACLE_SID = "None of the above" ]]; then
         exit ;
    else {
          break ;
         }
    fi
    break
    done
done

Produces a menu that looks like this, exactly as expected.

Code:
1) fsaaaaa
2) fsbbbbb
3) fsccccc
4) hrddddd
Select target (test) database being refreshed:

But now I want to add a "none of the above" item to the menu.
So add it in, thus:

Code:
while [[ $ORACLE_SID = "" ]]; do
  select ORACLE_SID in `egrep -i '^FS|^HR' /etc/oratab |\
      awk -F\: '{print $1}'|sort` "None of the above" ; do
    if [[ $ORACLE_SID = "" ]]; then
         echo
         echo "Please enter a valid number.  Retry.";
         echo
    elif [[ $ORACLE_SID = "None of the above" ]]; then
         exit ;
    else {
          break ;
         }
    fi
    break
    done
done

And the menu went from a single column to three columns:

Code:
1) fsaaaaa           3) fsccccc           5) None of the above
2) fsbbbbb           4) hrddddd
Select target (test) database being refreshed:

It behaves exactly as I planned, but I don't understand the change of format.
# 2  
Old 04-11-2014
What shell are you using? I know that bash tries to format it elegantly if it can, depending on available space, number of, and size of options.
# 3  
Old 04-11-2014
Just using sh. First line of script is
Code:
#!/bin/sh

I thought at first it might be an issue with the interaction with IFS, but I added the same "none of the above" option to another block elsewhere in the script ... one that only produces 3 choices (plus my 'none of the above') and it formats in a single column.

I could try it with bash and see what happens. Hopefully there won't be other slight differences that impact some of the other code ... Worst comes to worst, I can live with it like it is, but I'd like to learn something from it as well.

---------- Post updated at 12:44 PM ---------- Previous update was at 12:05 PM ----------

Just as a follow up, I just noticed that /bin/sh is just a symbolic pointing to /bin/bash, so I guess my script is being processed by bash
# 4  
Old 04-11-2014
/bin/sh just means "any shell compatible with generic bourne". It could be bash, ksh, or even old-fashioned, honest-to-goodness, written-in-1977 Bourne written by Steven Bourne himself.

So if you're using anything except generic Bourne features, you should probably specify what shell you're using more exactly.

The output of select can differ from shell to shell. If it's readable, I don't really see an issue.
# 5  
Old 04-14-2014
Quote:
Originally Posted by Corona688
/bin/sh just means "any shell compatible with generic bourne". It could be bash, ksh, or even old-fashioned, honest-to-goodness, written-in-1977 Bourne written by Steven Bourne himself.

So if you're using anything except generic Bourne features, you should probably specify what shell you're using more exactly.

The output of select can differ from shell to shell. If it's readable, I don't really see an issue.
As noted in my edit, I discovered that /bin/sh is a symbolic pointing specifically to /bin/bash.

My shell scripting is pretty much self-taught; consequently, a lot of the subtleties of the differences between the various shells escape me. I'm aware there are differences, but the specifics in any given instance aren't always clear.

"If it's readable ...."
I agree. Which is why I said I can live with it but would like to use this as a learning experience (see comment on 'self taught' -- Smilie )
# 6  
Old 04-14-2014
How about
Code:
export COLUMNS=20
$ select A in A B C D E F G "None of the above "; do :; done

# 7  
Old 04-15-2014
RudiC,

That fixed the display to what I was after.
FWIW, I found no reference to this in any discussion or example of 'select'. Of course, when you showed that, the first thing I did was go back to my references to see what I could find about COLUMNS. The only thing I could find was in my copy of Unix in a Nutshell, where it says "Screen's column width; used in line edit modes and select lists." That's it. Doesn't really explain how it is used, particularly in select lists. I did read in another reference that its default value is 80. Can you explain a bit more about the interaction going on here?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Stuck with menu in select

hi i am new to bash scripting .. i created a bunch of folders but only want the folder names with file1. so i go in and make an array to grab the folders the put in a file then i strip the directories so i just have the folder names i need then i would like to make the menu with a selection... (3 Replies)
Discussion started by: lamby22
3 Replies

2. Shell Programming and Scripting

Help with 'select' for menu input

A lot of my scripting makes use of the 'select' command to create menu driven input. A typical example of how I use it is as: somevar='' PS3='Select one: ' while ]; do select somevar in $(sqlplus -s $dbuser/$dbpw@mydb <<EOF set echo off feedback off verify off... (7 Replies)
Discussion started by: edstevens
7 Replies

3. Shell Programming and Scripting

File Select Menu Script

Hi All, I need to develop a bash script list “list of files” and able to select if any and set as globe variable in script and use for other function. I would like to see in menu format. Example out put Below are the listed files for database clone 1. Sys.txt 2. abc.txt 3. Ddd.txt... (1 Reply)
Discussion started by: ashanabey
1 Replies

4. Shell Programming and Scripting

Select ksh menu question

I am creating a Select menu with a few options and I would like to create a "better" looking interface than just this: 1) Option 1 2) Option 2 3) Option 3 Instead, I would like something like this: *********** * Cool Script * * 1) Option 1 * * 2) Option 2 * * 3) Option 3 *... (2 Replies)
Discussion started by: chipblah84
2 Replies

5. Shell Programming and Scripting

reprint the select menu after a selection

Hi, I am using a select in ksh for a script #!/bin/ksh FIRSTLIST='one two three four quit' PS3='Please select a number: ' select i in $FIRSTLIST ; do case $i in one) print 'this is one' ;; two) print 'this is 2' ;; three) print 'this is 3' ;; four) print... (7 Replies)
Discussion started by: omerzzz
7 Replies

6. Shell Programming and Scripting

Error using select menu command

Hi All, I am trying to use the select command & the menu. below mention is my script #!/bin/bash 2 3 PS3="Is today your birthday? " #PS3 system variable 4 5 echo "\n" 6 7 8 select menu_selection in YES NO QUIT 9 do 10 11 ... (1 Reply)
Discussion started by: milindb
1 Replies

7. Shell Programming and Scripting

Select command to build menu

Hello everyone. I am using the select command to build a menu, here is my question: Is it possible to generate a menu which contains several sections and have a separator between the sections without having a selection number generated in front of the separator? This is a sample of what I would... (1 Reply)
Discussion started by: gio001
1 Replies

8. Shell Programming and Scripting

reappearing menu list using select

is there a way I can make the menu list reappear when I use select ? ----- menulist="Change_title Remove_tag Change_tag Add_line Quit" select word in $menulist #change_title remove_tag change_tag add_line quit do case $word in # first menu option Change Title ... (9 Replies)
Discussion started by: forever_49ers
9 Replies

9. Shell Programming and Scripting

Drop down menu in bash for timezone select

Is there any way to implement a drop down menu selection in bash? This is on CDLinux which is a very minimal live CD and I am using it to install an image onto a hard drive. Part of that process is the timezone selection. There are just too many timezones to attempt to use the "select" command.... (1 Reply)
Discussion started by: simonb
1 Replies

10. Shell Programming and Scripting

dynamic Select menu

Hi all is menu driven by SELECT can be a dynamic ? My requirement is that i want SELECT to be created on run time not predefine . The select should be created as per the no of words in a file thanks in advance rawat (2 Replies)
Discussion started by: rawatds
2 Replies
Login or Register to Ask a Question