[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[bug #35668] odd behaviour with wildcard patterns accidently matching fi
From: |
Eric Blake |
Subject: |
[bug #35668] odd behaviour with wildcard patterns accidently matching file names |
Date: |
Wed, 29 Feb 2012 16:20:10 +0000 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:10.0.1) Gecko/20100101 Firefox/10.0.1 |
Update of bug #35668 (project grep):
Status: None => Invalid
Open/Closed: Open => Closed
_______________________________________________________
Follow-up Comment #1:
I'm closing this; it is not a bug in grep, but in your (mis-)use of the
shell.
~ $ echo -e "123n456" > test
echo -e is not portable. POSIX recommends that you use printf(1) instead:
printf "123n456n" > test
~ $ cat test | grep [0-9][0-9][0-9]
123
456
Useless use of cat.
Missing shell quoting. When you have no files that match the glob, then the
glob is passed through unchanged, so you are grepping for the pattern
'[0-9][0-9][0-9]'.
~ $ touch 456
~ $ cat test | grep [0-9][0-9][0-9]
456
Now that the glob matches, the shell expands it to the matching file name,
'456', so you are now grepping for the pattern '456'.
To see the difference, try:
echo [0-9][0-9][0-9]
both before and after creating one or more files with a 3-digit name. What
you meant to do was:
grep '[0-9][0-9][0-9]' < test
Or, more compactly,
grep '[0-9]{3}' < test
_______________________________________________________
Reply to this item at:
<http://savannah.gnu.org/bugs/?35668>
_______________________________________________
Message sent via/by Savannah
http://savannah.gnu.org/