* Carlos Hendson (skyc...@gmx.net) wrote:
> [1] The reason an error message is shown here is because it's bash
> that's reporting the broken pipe error.  Grep's error message was
> redirected to /dev/null, which was:
> 
> grep: unrecognized option '--unsupported'
> Usage: grep [OPTION]... PATTERN [FILE]...
> Try `grep --help' for more information.
> 
> So even when the system doesn't support --color, that original code will
> pollute the screen with bash's error message.

  SIGPIPE behaviour depends on the shell, how it was built and its
configuration so won't always receive an error.

  The point of this mail however is that there is still a way around it,
just call the commands within a subshell.  Compare:

  $ (echo hello | grep --colour l >/dev/null 2>&1) && echo colour support
  colour support
  $ (echo hello | grep --broken_arg l >/dev/null 2>&1) && echo broken_arg 
support

with the original non-subshell'd version:

  $ echo hello | grep --broken_arg l >/dev/null 2>&1 && echo broken_arg support
  -bash: echo: write error: Broken pipe

Thanks,

James

Attachment: pgpekrCaEfOdK.pgp
Description: PGP signature

Reply via email to