1 |
* Carlos Hendson (skyclan@×××.net) wrote: |
2 |
> [1] The reason an error message is shown here is because it's bash |
3 |
> that's reporting the broken pipe error. Grep's error message was |
4 |
> redirected to /dev/null, which was: |
5 |
> |
6 |
> grep: unrecognized option '--unsupported' |
7 |
> Usage: grep [OPTION]... PATTERN [FILE]... |
8 |
> Try `grep --help' for more information. |
9 |
> |
10 |
> So even when the system doesn't support --color, that original code will |
11 |
> pollute the screen with bash's error message. |
12 |
|
13 |
SIGPIPE behaviour depends on the shell, how it was built and its |
14 |
configuration so won't always receive an error. |
15 |
|
16 |
The point of this mail however is that there is still a way around it, |
17 |
just call the commands within a subshell. Compare: |
18 |
|
19 |
$ (echo hello | grep --colour l >/dev/null 2>&1) && echo colour support |
20 |
colour support |
21 |
$ (echo hello | grep --broken_arg l >/dev/null 2>&1) && echo broken_arg support |
22 |
|
23 |
with the original non-subshell'd version: |
24 |
|
25 |
$ echo hello | grep --broken_arg l >/dev/null 2>&1 && echo broken_arg support |
26 |
-bash: echo: write error: Broken pipe |
27 |
|
28 |
Thanks, |
29 |
|
30 |
James |