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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With