Gentoo Websites Logo
Go to: Gentoo Home Documentation Forums Lists Bugs Planet Store Wiki Get Gentoo!

Bug 182578

Summary: sys-apps/grep-2.5.1a-r1 behaves badly when there is an '=' character in the regex
Product: Gentoo Linux Reporter: David Flogeras <dflogeras2>
Component: [OLD] Core systemAssignee: Gentoo's Team for Core System packages <base-system>
Status: RESOLVED INVALID    
Severity: normal CC: truedfx
Priority: High    
Version: unspecified   
Hardware: x86   
OS: Linux   
Whiteboard:
Package list:
Runtime testing required: ---

Description David Flogeras 2007-06-19 14:05:29 UTC
I have a config file with the format:

key1 = value1
  key2   =  value2 #intentional whitespace for example

and I try to use grep (2.5.1a-r1) to check if certain keys exist with the following command:
grep '\s*key1\s*=' config.file

So in english, any whitespace, key, any whitespace, equals character

This does not work (it fails to recognize a line which should match). However changing the regex to:

grep '\s*key1\s*=*' config.file

Does work.

If I try the former regex on fedora (grep 2.5.1) it matches the pattern correctly.

Reproducible: Always

Steps to Reproduce:
1. Create a text file with a line like "gentoo = great" (without quotes)
2. grep '\s*gentoo\s*=' filename
3. grep '\s*gentoo\s*=*' filename

Actual Results:  
step two will not produce a match, while step three will
Comment 1 Harald van Dijk (RETIRED) gentoo-dev 2007-06-19 19:29:33 UTC
\s matches the lowercase letter s. To match a space character, use [[:space:]] or list the specific literal characters between [ and ]. There is no mention in the documentation of any special behaviour for \s. If Fedora's grep behaves differently, maybe they patched it, but a manually compiled grep without any patches behaves the same way for me as Gentoo's grep does.

And the reason \s*gentoo\s*=* does match your string is because it matches just "gentoo", since both the trailing letters 's' and the = are optional.