6

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 enter image description here

Tan Vee Han
  • 317
  • 3
  • 12
  • Have a look at [this answer](https://stackoverflow.com/a/27875395/1765658), there are several ways and tools. (Try the demo!!) – F. Hauri Nov 29 '20 at 17:20

2 Answers2

0

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. Example dialogue

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
  • 898
  • 1
  • 8
  • 22
-6

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
  • 103
  • 8