Instead of complicated case / if statements, you can make a trick and use an array to store filenames inside, and then just call the file you need using it's array index:
number=1
for file in ./menus/*; do
fnames+=($(basename -s .sh $file))
#OR just fnames+=( $file )
echo "$number)" `basename -s .sh "$file"`
let "number += 1"
done
read -p "select a file id" fid
fid=$(($fid-1)) # reduce user input by 1 since array starts counting from zero
cat "${fnames[$fid]}.sh" # or just cat "${fnames[$fid]}"
You can also make your jobe with a nice GUI using Yad (an advanced fork of Zenity) like bellow.
In this case you don't need numbering - you just select the file from a GUI list, and by pressing enter or click at ok you cat the selected file and you can see it's content on a new yad window.
As a single line command in bash (for testing):
fc=$(basename -s .sh $(find . -name "*.sh") |yad --list --width=500 --height=500 --center --column="File" --separator="") && cat $fc.sh |yad --text-info --width=800 --height=300
As a script:
yadb=0
while [ $yadb -eq "0" ];do
fc=$(basename -s .sh $(find . -name "*.sh") |yad --list --width=500 --height=500 --center --column="File" --separator="")
yadb=$?
if [ $yadb -eq "0" ]; then
cat $fc.sh |yad --text-info --width=800 --height=300
fi
# If you press cancel on yad window , then yadb will become 1 , file will not be displayed and while loop will be ended.
done