grep is inconsistently defaulting to grep -P?
Posted
by
Sammitch
on Server Fault
See other posts from Server Fault
or by Sammitch
Published on 2013-10-24T17:41:40Z
Indexed on
2013/10/26
3:57 UTC
Read the original article
Hit count: 673
I have a script that does some housekeeping that works perfectly well when invoked from an interactive shell, but did nothing when invoked by cron. To troubleshoot this I started a shell with a 'blank' environment with the command:
env -i /bin/bash --noprofile --norc
Using this blank env I've dug into my script and found that the following grep
will not match any files:
grep -il "^ws_status\s*=\s*[\"']remove[\"']$"
However, when run from an interactive shell the command will return the filenames of the matching files.
As a note, the expression is matching lines like: WS_STATUS = "remove"
Through trial-and-error I discovered that adding -P
to the options [Perl regex] the command started working normally in the 'blank' shell. However, I have no idea why my login shell appears to be defaulted to grep -P
.
- There is only one
grep
binary,/bin/grep
- There are no aliases defined for
grep=pgrep
orgrep="grep -P"
- There is no env variable
GREP_OPTIONS
defined.
What's the deal here?
Note: OS is RHEL v5.10, Bash is v3.2.25, grep is v2.5.1
© Server Fault or respective owner