How to Go Illini in Bash
I'm a newbie, and am just learning about scripts. Plus I like Illinois basketball.
So I'm writing this fun little script with Bash with an If - Then control structure. I ask who the best team is. If the user types the right team name they get one response. If they type a different team they get another response. I can get this to work: if test $team = Illinois then . . . But I want it to work whether they type Illini or illini or Illinois or illinois. I've tried all sorts of variations of quoting, brackets, escaping, etc with this: if test $team = [Ii]llinois -o [Ii]llini But haven't found what works. What characters do I need to use to make this work? |
Use perl. It's a whole lot easier for such regular expression comparisons.
-Sarav |
BAH! I scoff at your suggestion of using perl!!
(= Just kidding.. I love perl.. but then again, I'm stubborn and like to stretch bash.... actually, lbauer, this is really easy to do. in your test, you'll need to use the [[ ]] construct with an ==. You can see more about double brackets here. Here's an example of use to show you how it can be done. Code:
#!/bin/bash Code:
~/bash> ./pmatch.sh Happy bashing! |
BTW, here's a few links for you, of some things I reference:
http://itb.biologie.hu-berlin.de/~be...ware/bash.html http://www.tldp.org/LDP/abs/html/ and, regexp substitution, etc: http://www.tldp.org/LDP/abs/html/par...stitution.html This last one is a great reference to show how powerful bash scripting can really be. |
Thanks for the bracket suggestion.
This works: echo -n "Who's the best College basketball team in the nation? " read team if [[ $team == *llin* ]] then echo "Go Illini, #1!!" else echo "Boo! That's not the best team" echo "Go Illini!" fi |
All times are GMT -5. The time now is 11:57 AM. |