Hello,

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

command
fi

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

Apologies:

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

Problem solved.

Thanks

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.