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
  • 337
  • 4
  • 12

2 Answers2

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. 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
  • 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