[PLUG] Bash matching...

Tony Rick tonyr42 at gmail.com
Fri Oct 26 23:58:23 UTC 2012


On Fri, Oct 26, 2012 at 3:52 PM, Russell Johnson <russ at dimstar.net> 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
> russ at dimstar.net
>
>
>
> _______________________________________________
> PLUG mailing list
> PLUG at lists.pdxlinux.org
> 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)



More information about the PLUG mailing list