Reading from standard input

So, I am new to shell scripting and have a few problems.
I know how to read from standard input but I do not know how to really compare it to say, a character. I am trying to compare it to a character and anything exceeding just a character, the user will get an output message, but the program goes on.

I tried using test with regular expressions after taking an input like this.

read input

while test $input != q || test -z $input
do
        if test $input = n
        then
 ...

I also want my program to move on if the input just presses enter, but I get two error messages on the while statement and the if statement saying unary operator expected.

You need to check the length of a string, then.

There's really no reason to use test, at all, ever these days.

STR="zzz"

while [ "$#STR" -ne 1 ]
do
        printf "Enter one letter:   "
        read STR
done

May I ask the reason to not use test? I recognize the square brace as an alternative method, I'm just curious as I'm just starting to learn.

And # is?

Each time you run test you're creating a new process and waiting for it to quit. [ ] are usually shell built-ins these days, so no new process is needed -- meaning, hundreds of times faster.

# is length.

Corona,

I tried testing your code, and it says on the loop with the case statement "integer expression expected"

Corona probably meant

${#STR}

You could also do without testing for the length, just take the first character like this:

while [ ${STR:0:1} != q ] ; then ...

I'm sorry, but could you explain what the colons mean?

See this table.

Of course, if your shell isn't bash or ksh, you could have few or none of these.