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.

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
  • 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. – Dan Rosenstark May 17 '10 at 14:48
  • BTW, yes, the IFS value is not looking healthy in TextMate. I'll leave it alone. – Dan Rosenstark 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.

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

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

$ set | cat -v | grep foo

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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