tag 26005 notabug thanks On 03/06/2017 04:31 PM, Ildar Rakhmanov wrote: > Hi, I tested this with latest grep 3.0 in linux RHEL and some Ubuntu > servers as well. > > To reproduce run in empty directory > > echo "start_string_20091210.end" | grep -o > [1-2][0][0-1][0-9][0-1][0-9][0-3][0-9]
Underquoted. This asks the shell to perform globbing for all files that match those patterns. Initially, none do, so the shell passes the pattern on unchanged to grep. > mkdir 20011209 Now the glob succeeds, so you are invoking echo ... | grep -o 20011209 which is NOT what you meant (it searches for the regex 20011209 in the input, which is not present). > echo "start_string_20091210.end" | grep -o > [1-2][0][0-1][0-9][0-1][0-9][0-3][0-9] > rmdir 20011209 For even more fun, try: touch 20011209 20011210 now your grep will also output nothing. Why? because you end up invoking: echo ... | grep -o 20011209 20011210 which completely ignores stdin and searches for the string 20011209 in the (empty) file 20011210. If you had typed: echo ... | grep -o '[1-2][0][0-1][0-9][0-1][0-9][0-3][0-9]' then you would be immune from shell globbing changing the parameters based on the contents of the current directory. As the problem is in your improper use of shell quoting, and not in grep, I'm closing this as not a bug. However, feel free to respond if you still have questions. -- Eric Blake eblake redhat com +1-919-301-3266 Libvirt virtualization library http://libvirt.org
signature.asc
Description: OpenPGP digital signature