Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 or grep="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

share|improve this question
so in your interactive shell, which grep returns grep -P? Did you do a recursive grep for "grep -P" in /etc/profile*? – Petter H Oct 24 '13 at 18:23
@PetterH which grep returns /bin/grep, and grep -ri grep /etc/profile* only prints out a few uses of it in the scripts. – Sammitch Oct 24 '13 at 18:49
Rather than which grep can you try type grep. – Mark Wagner Oct 24 '13 at 19:29
@MarkWagner grep is hashed (/bin/grep) – Sammitch Oct 24 '13 at 20:18
I don't have enough rep to comment, but does it help if you use \grep with a backslash, instead of grep? I know you already said that it wasn't aliased, but in the off chance that it is, this should use an unaliased grep. – sinisterstuf Jun 16 '14 at 10:46

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.