7

I am doing something I always do in Bash:

set | grep -i path 

and the output is

Binary file (standard input) matches

What's wrong? grep --help works, and set | more works too.

3 Answers 3

12

Do this:

set > /tmp/zshset

Then open /tmp/zshset in your favorite editor. Look for IFS.

The default value for this, per the zshparam man page, is default space, tab, newline and NUL. This last one is causing the trouble. grep sees the NUL (ascii 0, displayed often as ^@) and thinks that this is a binary file.

Possible solutions:

  • Set IFS to some other value. This might cause problems if something else you do expects that NUL is a valid delimiter.
  • Use grep -a as suggested by KeithB (or its equivalent --binary-files=text)
  • Create a new alias for yourself which uses grep -a to save yourself a little bit of typing
  • Adapt to looking at your PATH through other means (e.g. env | grep -i path, echo $PATH) -- I think the other solutions are simpler
3
  • Clear and complete explanation. Thanks - I learned something today.
    – JRobert
    May 17, 2010 at 14:28
  • I'll second that +1. Using the alternatives you suggest makes me know more, so I'll use those for now. I don't want to mess with unrelated variables just to get a command to work. May 17, 2010 at 14:48
  • BTW, yes, the IFS value is not looking healthy in TextMate. I'll leave it alone. May 17, 2010 at 14:49
2

I'm not sure what is going on, but you can pass the -a flag to grep to force it to treat its input as text, regardless of what it thinks that it is.

1
  • Yeah, I just tried with grep --binary-files=text which works, but I wonder why this doesn't work off the bat.... Thanks May 17, 2010 at 13:56
0

Another workaround if your grep doesn't implement -a is to do:

$ set | cat -v | grep foo

You must log in to answer this question.

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