0

I googled for the following error, and didn't get any great explanations as to what was going on with grep under tcsh. (Yes, that date expression exists in the log files).

$ grep '2014-07-21' *.log
grep: Invalid back reference

Curiously, if I switch to bash, the command works fine (that is my current work-around). Anyone know what's going on here?

Because someone will ask, here are the results of which and alias:

$ which grep
/bin/grep

$ alias grep
$               # (Nothing)

This is running on RHEL 5.4 (Red Hat).

4
  • It looks as if tcsh expands single-quoted text into unquoted text with a back-slash before each character, in your case \2\0\1\4\-\0\7\-\2\1. grep interprets \{digit} as the offending back reference. The command should be OK without the quotes, which are unnecessary for your search strong. bash gives the same error if you use both the quotes and the back-slashes. Note that I have inferred this conclusion, but I don't have tcsh loaded to confirm it.
    – AFH
    Jul 23, 2014 at 15:18
  • Indeed, taking off the quotes works! Interesting. However, if my grep was something more complicated like: grep -P "2014-07-\d*", then tcsh forces me back to using quotes, and it works again. Very curious. Jul 23, 2014 at 15:49
  • I can only guess how tcsh might handle double-quotes, but your original search might well work with them.
    – AFH
    Jul 23, 2014 at 16:05
  • @AFH - Finally found it! It's a RedHat 5.4 bug that has to do with buggy glob matching (i.e.: '*.log'). Jul 24, 2014 at 13:10

1 Answer 1

0

This is apparently a known bug in Tcsh in the particular version of Tcsh and RedHat that I am using. Apparently there is a patched version of tcsh available for this issue, as described in this errata, for RedHat 5.4:

Expansion of multiple filename globs failed if any glob in a command line
expression failed. The correct behavior outlines that a glob command should
only fail if all components of the command fail. This behavior is restored
with this updated package. (BZ#529703)

I checked, and I do indeed have the buggy version of tcsh installed as noted in the bug report above:

$ rpm -qa tcsh
tcsh-6.14-14.el5_4.2

Evidently the IT department for my company has not installed this tcsh patch yet (though I recently learned we'll soon be finally upgrading to RedHat EL 6.x).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .