- The problem statement, all variables and given/known data:
Find the first letter in alphabet from the input:
Accept the input of a series of upper case alphabetic letters one at a time. The input ends with a 0. Find and display the first letter in alphabetic order. For example, input of D, G, T, S, V, G, C, K, P should result in C.
- Relevant commands, code, scripts, algorithms:
P.S. I am using cygwin in windows to do this script.
- The attempts at a solution (include all code and scripts):
Im not sure how to tackle this question so im asking for tips and pin pointers.
Basically what i think i should do is use a while loop and the shift command to take in the letters one at a time (But i heard shift deletes the first input so im not sure if its possible) then use an nested if statement
if [ $input \< �z� && $input \> �a� ]
to get rid of any non alphabetical inputs with an else to give an error.
THen thats where im stuck. How would someone find out the first letter from a given amount of letters?4. Insearch: (University of Technology Sydney), Sydney NSW, Australia, James Hu (web systems), www(dot)insearch.edu.au/default.aspx?ArticleID=430
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).
---------- Post updated at 08:24 PM ---------- Previous update was at 06:14 PM ----------
"3")
letter="Z"
if [ $letter \< "Z" && $letter \> "A" ]; then
while [ $letter == "Z" ] || [ $letter < "Z" ] && [ $letter -ne 0 ]; do
read letter2
if [ $letter2 \< $letter ]; then
letter=letter2
else
break
fi
done
elif [ $letter -eq 0 ]; then
echo Lowest letter is $letter
else
echo "Invalid input. Please enter A-Z (capital) one at a time finalised by a 0"
fi
;;
this is what ive managed thus far
i get the following errors though
./Assignment4.SH: line 48: [: missing `]'
./Assignment4.SH: line 57: [: Z: integer expression expected
Invalid input. Please enter A-Z (capital) one at a time finalised by a 0
Press Enter to continue...
after further thought i think i should use case instead to validate the use of A-Z such as a [A-Z]) code code;; is that a better idea?