Is there a way to use metacharacters in a loop or in an if[ ].
I want to allow a user to enter Y, y, Yes, yes, Yah, etc...
in a loop I tried:
read response
while [ "$response" = "[Yy]*" ]
do........
and
while [ "$response" = "\[Yy\]*" ]
do .........
this works for grep or egrep but not in loops
Why??????
"Why" is a tough question to answer.
But the Korn shell corrected this problem and several others by introducing the [[ syntax:
while [[ $response = [Yy]* ]]
will work. And there is no need to quote $response. Unlike the "[" command, "[[" works fine if $response is empty.
And a warning:
while [[ [Yy]* = $response ]]
will not work. The pattern must be on the right of the equals sign.
while [[ $response = [Yy]* ]]
doesn't work for me--but I'm using the Bourne shell.
The only Bourne shell built-in that uses patterns is the case statement. That's a possibility. But you may want to try a modern shell.
Thanks...Perderabo
You're an amazing resource!!!