Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I use RegEx Buddy to prototype and debug my regular expressions. RegEx Buddy allows me to choose between a number of different regular expression engine types (.NET, Java, Perl, GNU BRE, GNU ERE, POSIX, BRE, POSIX ERE etc).

What regular expression engine does bash use (for example in if and case statements)? I'm running Centos 5.5 32 bit and bash 3.2.25(1):

[kevin@mon01 scratch]$ bash --version
GNU bash, version 3.2.25(1)-release (i686-redhat-linux-gnu)
Copyright (C) 2005 Free Software Foundation, Inc.

I'm guessing it'll be GNU BRE or GNU ERE?

share|improve this question

3 Answers 3

up vote 7 down vote accepted

bash (and POSIX shells in general) do not use regular expressions in the case statement, rather glob patterns.

There's limited support for regular expressions using the =~ operator; see details at: http://mywiki.wooledge.org/BashGuide/Patterns,
which says that bash uses Extended Regular Expressions (ERE).

share|improve this answer
    
Thanks. Second link mentions ERE which I am guessing is GNU ERE. –  Kev Jun 23 '11 at 9:03

Bash doesn't use any of the above kinds of regular expressions in the if and the case statements.

Rather, it uses shell glob patterns, which are less powerful than any kind of regular expresion. Relatively new versions of bash also allow the use of extended glob patterns which are expressively equal to regular expressions without (line) anchors but including negated terms, but with a syntax different from any of the above mentioned regular expression types.

Note however that extended shell globs must be enabled prior use with shopt -s extglob both in a shell script or interactively.

In a single exceptional place, namely within the [[ ]] conditional command, the =~ binary relation allows to check a string on the left side against an extended regular expression ERE on the right side.

share|improve this answer

According to the linked Bash guide, Bash (since version 3.0+) uses: "the Extended Regular Expression (ERE) dialect."

More information on that dialect can be found here.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.