I need to create a list of option and allow the user to choose from the list using an arrow key, just like how we select the presets when creating a vue project
Asked
Active
Viewed 3,213 times
6

Tan Vee Han
- 337
- 4
- 12
-
Have a look at [this answer](https://stackoverflow.com/a/27875395/1765658), there are several ways and tools. (Try the demo!!) – F. Hauri - Give Up GitHub Nov 29 '20 at 17:20
2 Answers
1
Maybe the dialogue
utility will help you. It lets you build a menu with options that looks like this, given the following command:
dialog --checklist "Choose toppings:" 10 40 3 \
1 Cheese on \
2 "Tomato Sauce" on \
3 Anchovies off
This example is a multi-select, but there is a radio-select option too.
This page provides examples and a greater description than I ever could:
https://www.linuxjournal.com/article/2807
I refer to it any time I want to build an interactive options in a script; maybe it will help.

Lucas
- 1,149
- 1
- 9
- 23
-5
From what I understand you want something like this
#!/bin/bash
# Bash Script with selection
PS3='What would you like for breakfast? '
menu=("Bacon and Eggs" "PB&J Sandwich" "Cereal" "Quit")
select option in "${menu[@]}"
do
case $option in
"Bacon and Eggs")
echo "Option 1 selected"
;;
"PB&J Sandwich")
echo "Option 2 selected"
;;
"Cereal")
echo "Option 3 selected"
;;
"Quit")
break
;;
*) echo "invalid option $REPLY";;
esac
done
You can check it out by saving it as menu.sh and run by
sh menu.sh

utkayd
- 153
- 8
-
8but this wont allow the user to select the option using arrow key right? – Tan Vee Han Oct 25 '19 at 11:47
-