Here is a sample script that shows a few ways to do what you're trying to do that work with both bash and ksh:
printf "Enter answer: "
while read answer
do if [ "$answer" = "y" ] || [ "$answer" = "Y" ]
then printf "true: %s\n" \
'if [ "$answer" = "y" ] || [ "$answer" = "Y" ]'
else printf "false: %s\n" \
'if [ "$answer" = "y" ] || [ "$answer" = "Y" ]'
fi
if [[ "$answer" == [yY] ]]
then printf "true: %s\n" \
'if [[ "$answer" == [yY] ]]'
else printf "false: %s\n" \
'if [[ "$answer" == [yY] ]]'
fi
if [[ "$answer" == [yY]* ]]
then printf "true: %s\n" \
'if [[ "$answer" == [yY]* ]]'
else printf "false: %s\n" \
'if [[ "$answer" == [yY]* ]]'
fi
case "$answer" in
([yY]) printf "match: case %s\n" '([yY])';;
([nN]) printf "match: case %s\n" '([nN])';;
(*) printf "no match: cases ([yY]) and ([nN])\n"
esac
case "$answer" in
([yY]*) printf "match: case %s\n" '([yY]*)';;
([nN]*) printf "match: case %s\n" '([nN]*)';;
(*) printf "no match: cases ([yY]*) and ([nN]*)\n"
esac
printf "Enter another answer: "
done
printf "\nDone.\n"
The [[ expr ]] tests are not available in a Bourne shell and are not required by the POSIX standards; the other forms are required by the POSIX standards and will also work with an old Bourne shell.
Yes. According to the standards, test's = operator compares strings; not filename matching patterns and not regular expressions. The test utilities in some shells support operators and expressions in addition to those specified by the standards, but they aren't portable.
The [[ expression ]] forms aren't in the standards yet, but are being considered for inclusion in the next revision of the POSIX standards and the Single UNIX Specification.