45.33 Testing Two Strings with One case StatementThe shell's case statement ( 44.5 ) has some advantages over the test command ( 44.20 ) - for instance, case can do pattern matching. But test has the -a and -o "and" and "or" operators; those don't seem easy to do with case . And test isn't built in to some older shells, so using case may be faster. Here's a way to test two things with one case statement. It won't solve all your problems. If you think carefully about the possible values the variables you're testing can have, though, this might do the trick. Use a separator (delimiter) character between the two variables.
In the example below, I've picked a slash (
case "$#/$1" in 1/-f) redodb=yes ;; 0/) ;; *) echo "Usage: $myname [-f]" 1>&2; exit 1 ;; esac
If there's one argument ( Of course, you can do a lot more this way than just testing command-line arguments. - |
|