Why menu won't allow 2 character input?

I�m trying to write a script for users to easily check folder size.
The idea is to have a menu that starts at the top directory and then drills down to lower directories.

Selections 1-9 work fine.
The issue I�m having is any 2 digit menu selections (10+) doesn�t work and it returns the error message �Invalid Selection�

Can someone explain why I�m unable to enter a 2 character menu option?

  • For the code example I removed options 3-9.
    I know I could use alpha characters to have more than 9 options but I�m trying to understand the error.

Thank you for your time and knowledge.

#!/bin/bash
#================================================
trap "rm ./f 2> /dev/null; 0 t" 0 1 3
loop=y
while test $loop = "y"
do
  clear
  tput cup 3 12; echo "Select Path for Top 25 Folder Sizes"
  tput cup 4 12; echo "=================================="
  tput cup 6 9; echo " 1 = /path/to/dir1"
  tput cup 7 9; echo " 2 = /path/to/dir1/subdir1"
  tput cup 8 9; echo "10 = /path/to/dir1/subdir2"
  tput cup 9 9; echo "11 = /path/to/dir1/subdir3"
  tput cup 10 9; echo " Q = Quit"
  tput cup 12 9; echo "Selection:"
  tput cup 12 19;
  read choice || continue
  case $choice in
    [1]) path= /path/to/dir1" ;;
    [2]) path="/path/to/dir1/subdir1" ;;
    [10]) path="/path/to/dir1/subdir2" ;;
    [11]) path="/path/to/dir1/subdir3" ;;

    [Qq]) clear ; exit ;;

    *)tput cup 14 9; echo "Invalid Selection"; read choice ;;
  esac
  echo $path

  cd $path && ls | xargs -I {} du -s {} | sort -nr | head -25 | awk '{sum=$1;
  hum[1024**4]="T"; hum[1024**3]="G";hum[1024**2]="M";hum[1024]="K";
  for (x=1024**4; x>=1024; x/=1024){if (sum>=x) { printf "%.1f%s\t\t",sum/x,hum[x];print $2;break}}}' | less
done

With a few corrections just the loop only the square brackets are not used when using dedicated letters or pseudo-numbers...
The second 'read' is not really necessary.

#!/bin/bash
loop=y
while test $loop = "y"
do
clear
tput cup 3 12; echo "Select Path for Top 25 Folder Sizes."
tput cup 4 12; echo "===================================="
tput cup 6 9; echo " 1 = /path/to/dir1"
tput cup 7 9; echo " 2 = /path/to/dir1/subdir1"
tput cup 8 9; echo "10 = /path/to/dir1/subdir2"
tput cup 9 9; echo "11 = /path/to/dir1/subdir3"
tput cup 10 9; echo " Q = Quit"
tput cup 12 9; echo "Selection:"
tput cup 12 19;
read choice || continue
case $choice in
	1) path="/path/to/dir1" ;;
	2) path="/path/to/dir1/subdir1" ;;
	10) path="/path/to/dir1/subdir2" ;;
	11) path="/path/to/dir1/subdir3" ;;
	[Qq]) clear ; exit ;;
	*)tput cup 14 9; echo "Invalid Selection..." ; path="" ;;
esac
echo $path
sleep 3
done

Thank you for helping me better understand what was occurring.
I made the changes and it works perfectly.

No problem but you can simplify your loop and eliminate the variable loop=y ...

If your terminal accepts terminal escape sequences you can do away with tput.

I didn't change these as it would have confused the issue but I am glad to have helped...