bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: How to match regex in bash? (any character)


From: Dennis Williamson
Subject: Re: How to match regex in bash? (any character)
Date: Mon, 26 Sep 2011 21:37:07 -0500

On Mon, Sep 26, 2011 at 8:19 PM, Peng Yu <pengyu.ut@gmail.com> wrote:
> Hi,
>
> I know that I should use =~ to match regex (bash version 4).
>
> However, the man page is not very clear. I don't find how to match
> (matching any single character). For example, the following regex
> doesn't match xxxxtxt. Does anybody know how to match any character
> (should be '.' in perl) in bash.
>
> [[ "$1" =~ "xxx.txt" ]]
>
>
> --
> Regards,
> Peng
>
>

When you quote the string on the right hand side of =~ it changes to a
simple string match instead of a regex match. It is sometimes
difficult to specify a regex literally (and unquoted), so it's best to
use a variable as shown in Steven's reply to you.

The quoting is most likely unnecessary on the left hand side as well.

-- 
Visit serverfault.com to get your system administration questions answered.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]