-1
cat > abc.txt <<EOF
2014-04-11 00:00:00
2014-02-19 00:22:00
EOF

When I execute

grep -E :[0-9]{2}: abc.txt

I get

2014-02-19 00:22:00

I was expecting

2014-04-11 00:00:00
2014-02-19 00:22:00

This happens on fish shell (2.4.0), on bash it works fine. I am quite intrigued with whats going on here

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
khrist safalhai
  • 560
  • 5
  • 19
  • 1
    Try quoting `:[0-9]{2}:` so that it doesn't get expanded by the shell – Fredrik Pihl Aug 31 '17 at 11:15
  • 2
    If your question can be answered only by someone who's an expert in fish, don't tag bash as well; the general rule is that expertise in a tagged area should be reasonably expected to be helpful towards answering. – Charles Duffy Aug 31 '17 at 11:41

1 Answers1

7

In fish {a,b,c} is an enumerator. Example of use from the documentation:

$ echo input.{c,h,txt}
input.c input.h input.txt

So, your regular expression expands as :[0-9]2::

$ echo :[0-9]{2}:
:[0-9]2:
$ echo :[0-9]{2,3,4}:
:[0-9]2: :[0-9]3: :[0-9]4:

Escape the curly braces to avoid this:

$ echo :[0-9]\{2\}:
:[0-9]{2}:

Or, as suggested by Fredrik, quote the whole regular expression:

$ echo ':[0-9]{2}:'
:[0-9]{2}:
Renaud Pacalet
  • 25,260
  • 3
  • 34
  • 51