Skip to content

Instantly share code, notes, and snippets.

@nhoag
Last active October 16, 2020 17:46
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nhoag/c202b3dd346668d6d8c1 to your computer and use it in GitHub Desktop.
Save nhoag/c202b3dd346668d6d8c1 to your computer and use it in GitHub Desktop.
Dynamic menu in bash
#!/bin/bash
ENTITIES=$(ls -1)
SELECTION=1
while read -r line; do
echo "$SELECTION) $line"
((SELECTION++))
done <<< "$ENTITIES"
((SELECTION--))
echo
printf 'Select an entity from the above list: '
read -r opt
if [[ `seq 1 $SELECTION` =~ $opt ]]; then
sed -n "${opt}p" <<< "$ENTITIES"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment