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.

link|improve this question

74% accept rate
feedback

2 Answers

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
link|improve this answer
Clear and complete explanation. Thanks - I learned something today. – JRobert May 17 '10 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. – Yar May 17 '10 at 14:48
BTW, yes, the IFS value is not looking healthy in TextMate. I'll leave it alone. – Yar May 17 '10 at 14:49
feedback

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.

link|improve this answer
Yeah, I just tried with grep --binary-files=text which works, but I wonder why this doesn't work off the bat.... Thanks – Yar May 17 '10 at 13:56
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.