On Mon, Sep 26, 2011 at 8:19 PM, Peng Yu <pengyu...@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.