Skip to content

Instantly share code, notes, and snippets.

@CoeJoder
CoeJoder / choose_from_menu.sh
Last active August 13, 2025 12:20
`choose_from_menu()` bash function
# in-place shell selection list
# original by Guss: https://askubuntu.com/a/1386907
# improvements: syntax cleanup, shellcheck-linted, cyclic menu selection, compatible with `set -e`
#
# example usage:
# apples=("Red Delicious" "Granny" "Cosmic Crisp")
# choose_from_menu "Select an apple:" chosen "${apples[@]}"
# echo "You chose: $chosen"
function choose_from_menu() {
local -r prompt="$1" outvar="$2" options=("${@:3}")