I would like to use a simple "if then" test to check if an argument to a command begins with "http://" as follows:

if [[ $2 == [url]http://*[/url] ]]; then


but the wildcard just seems to be ignored, ie., it will only execute the command if the expression is strictly "http://" with nothing following it. I have tried enclosing the second expression with single and double quotes, and have tried using various wildcards such as ".", "?", ".*", etc. to no avail.

Done much searching on the web; the only thing I found referring to the use of wildcards in testing is in using the "test" command, of which it said you could not do so. Is this the case also with "if then" tests? Is there a way to implement wildcard testing using this command?

Any suggestions?

Thank you,

Allasso Travesser


I wasn't using the double brackets (thought I was...)

Problem solved.


Depending on how old-school you want to get, you can also check out the "expr" command -- It's generally used for arithmetic, but also does string matching - depending on the version it can be pretty cryptic (Gnu is the most intuitive).

e.g. (from the manpage for Sun - check out Gnu as they have "match" and "length" arguments, etc - much easier to understand - especially later ;)

expr //$a : '.*/\(.*\)'

, Mike