Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question

3 Answers 3

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
share|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

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.

share|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

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

$ set | cat -v | grep foo
share|improve this answer

Your Answer

 
discard

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

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