0

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

2
Contributors
2
Replies
3
Views
9 Years
Discussion Span
Last Post by eggi
0

Apologies:

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

Problem solved.

Thanks

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.