On Fri, Oct 26, 2012 at 3:52 PM, Russell Johnson <[email protected]> wrote:

> I have working scripts with examples of this, so I know something like
> this can be done...
>
> I have the following line in a bash script:
>
> if [[ "${hn}" =~ *"rds"* ]]; then
>
> The idea being that if ${hn} contains the literal rds, it should match...
>
> It's not working. i.e., when I run the script with -x, it doesn't match
> the string "something.rds.somethingelse"
>
> Does someone see what I'm missing here?
>
> Russell Johnson
> [email protected]
>
>
>
> _______________________________________________
> PLUG mailing list
> [email protected]
> http://lists.pdxlinux.org/mailman/listinfo/plug
>


Leave out the quotes and the splats. As far as I can tell, the =~ operator
will match the target pattern (rds) anywhere in the search string.  If you
need more context for the search target, you will need to add it explicitly.

if [[ ${hn} =~ rds ]]
should find rds anywhere in ${hn}.  This for bash v3 and later, which
should cover you (bash --version tells all).  The current version seems to
be 4 something,
-- 
- tony
"I come from the nowhere, I go to the noplace, und here I am!"
Aladdin and His Wonderful Lamp (Popeye, 1939)
_______________________________________________
PLUG mailing list
[email protected]
http://lists.pdxlinux.org/mailman/listinfo/plug

Reply via email to