Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash Select Menu Formatting without Tabs

Tags:

bash

I've built a simple select menu in Bash. It's currently displaying the menu horizontally (with tabs) like so:

1) Create a VM from scratch   3) Command-line Usage
2) Management Menu            4) Quit

I'd like the list to look like this:

1) Create a VM from scratch  
2) Management Menu
3) Command-line Usage     
4) Quit

UPDATE: Here's my code:

PS3="Please choose a valid option : "
OPTIONS=("Create a VM from scratch" "Management Menu" "Command-line Usage" "Quit")
select opt in "${OPTIONS[@]}"; do
    case $opt in
            "Create a VM from scratch")
                 createit
                 exit
                 ;;
            "Management Menu")
                 mgmtmenu
                 exit
                 ;;
            "Command-line Usage ")
                 help
                 ;;
            "Quit")
                exit
                ;;
            *) echo invalid option;;
    esac
done

How can I display the select menu with each option on it's own line?

like image 681
Ken J Avatar asked Jun 03 '16 14:06

Ken J


1 Answers

Bash defines a $COLUMNS environment variable that is read by select.

As seen in bash's man :

COLUMNS
         Used by the select compound command to  determine  the  terminal
         width  when  printing selection lists.  Automatically set if the
         checkwinsize option is enabled or in an interactive  shell  upon
         receipt of a SIGWINCH.
like image 174
Aaron Avatar answered Sep 23 '22 13:09

Aaron