Select Your Language

Infrastructure and Management

Cloud Computing

Storage

Runtimes

Integration and Automation

  • Comments
  • Bash regular expressions in RHEL 6 - TAM tip

    Posted on

    Quoted regular expressions no longer work in '[[ ]]' in Red hat Enterprise Linux 6. The way to do this now is to assign the regex pattern to a variable and then use the variable in a test.

     

    Example
     

     

    This will work in Bash 3 but not in Bash 4 because Bash 4 considers 'Link encap:Ethernet HWaddr (.*)' as a string instead of Regular expression:

     

     

    if ![[ $info =~ 'Link encap:Ethernet HWaddr (.*)' ]]
     

     

    To make the expression work in Bash 4 do the following:

     

    info2='Link encap:Ethernet HWaddr (.*)'
    if ![[ $info =~ $info2 ]]

    by

    points

    Responses

    Red Hat LinkedIn YouTube Facebook X, formerly Twitter

    Quick Links

    Help

    Site Info

    Related Sites

    © 2026 Red Hat