#!/usr/bin/bash
###script to input four characters. wxyz
echo "input first string"
read instring1
echo "input second string"
read instring2
##
echo "first string is:" $instring1
echo "second string is:" $instring2
##IF instring1 or instring2 are NOT 4 characters (xxxx) , exit 1.
##how??
If it is any easier, the four input characters "should" be numbers, like 0032 and 0198, or 2359 and 0900 , but I'd settle for trusting that the user knows to input digits and not alphas....
> if [ `echo "hello" | wc -c` -gt 4 ]; then echo "too many characters"; fi
too many characters
> if [ `echo "hell" | wc -c` -gt 4 ]; then echo "too many characters"; fi
too many characters
Huh???
> if [ `echo "hell" | wc -c` -gt 5 ]; then echo "too many characters"; fi
>
That is because the echo adds a new-line after it sends the output; to start to a new line. Thus, you have to check for one more character.