Bash Select Menu Formatting without Tabs

时光总嘲笑我的痴心妄想 提交于 2021-02-05 04:57:14

问题


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?


回答1:


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.


来源:https://stackoverflow.com/questions/37616552/bash-select-menu-formatting-without-tabs

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!