On Tuesday 28 July 2009 17:26:30 David C. Rankin wrote:
Bash gurus,
What is a shorter way to do multiple case insensitive tests on a string or variable that would accomplish this:
[[ $line == QUIT ]] || [[ $line == Quit ]] || [[ $line == quit ]] && break
Basically what I am looking for is some case insensitive way to test for quit or exit without having to define a test for each possible permutation without bringing in a big hammer like sed or the like. I am a bit confused on the test expansion but know things like $line == [Qq]uit won't work.
I can do it in case:
case $line in [Qq][Uu][Ii][Tt] ) break;; esac
But that seems like a clunky use of case. Is there a better way?
~> cat test.sh #!/bin/bash compare() { mytext=$(echo $1|tr [:upper:] [:lower:]) if [ "quit" = "$mytext" ]; then echo "yes"; else echo "no" fi } compare "QuIt" compare "QUIT" compare "quit" compare "foo" ~> ./test.sh yes yes yes no Anders -- To unsubscribe, e-mail: opensuse+unsubscribe@opensuse.org For additional commands, e-mail: opensuse+help@opensuse.org