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