i get stuck with this shell script code

i get stuck here . Anyone could check my work?
the user type a group of upper case letters at a time with 0 at the end. Find and display the first letter in alphabetic order.
For example, input of F, G, K, S, U, G, D, Q, P , the result should be D
Any invalid input character (eg. #, $, 3, a, etc.) should cause an error message and be ignored.

echo "please enter an alphabet"
input3=1
echo "" > temp
while [ "$input3" != "0" ]; do
read input3
echo $input3 > check
if [ "$input3" != "0" ]; then
if [ check1=`grep -w "[A-Z]" check ]; then
echo $input3 >> temp
else
echo input should be upper case alphabet
fi
fi
done
grep -w "[A-Z]" temp > temp1
echo the first letter in alphabetic order is `sort temp1 | head -1`;;

To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags

```text
 and 
```

by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 10:51 AM ---------- Previous update was at 09:11 AM ----------

#!/usr/bin/ksh

TMP="bla"

# Clean up old temp file
clean_up()
{
        if [[ -e $TMP ]]; then
                rm $TMP
        fi
}

clean_up

echo "Enter one upper case character per line and hit enter; to stop enter a zero."

while :; do
        read INPUT
        case $INPUT in
                [A-Z])          echo $INPUT >> $TMP
                                ;;
                0)              echo '------ OUTPUT ------'
                                sort $TMP| uniq| head -1
                                break
                                ;;
                *)              echo "no upper case letter and/or more than 1 character!"
                                ;;
        esac
done

clean_up

exit 0

thanks for your help....love you so much!!keke

---------- Post updated 08-25-09 at 02:21 AM ---------- Previous update was 08-24-09 at 09:36 AM ----------

hi Zaxxon!
your code still work with lower case characters , can you check it again!?

Works on my box:

Enter one upper case character per line and hit enter; to stop enter a zero.
3
no upper case letter and/or more than 1 character!
d
no upper case letter and/or more than 1 character!
F
s
no upper case letter and/or more than 1 character!
S
h
no upper case letter and/or more than 1 character!
$
no upper case letter and/or more than 1 character!
p
no upper case letter and/or more than 1 character!
P
0
------ OUTPUT ------
F

I guess you did not use ksh - I have the same problem like you on bash. Not sure why though. When using ksh like in the shebang (#!/usr/bin/ksh) all is fine. Maybe someone else knows why, sorry.

Update:
Found a way in bash - change the line inside the case/esac to:

                [A-Z])          echo $INPUT >> $TMP
# to
                [[:upper:]])          echo $INPUT >> $TMP

yeah! now i undertand my problem! thanks for your help.

HOMEWORK CANNOT BE POSTED WITHOUT USING THE HOMEWORK TEMPLATE

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.