# Extending sed's exit codes functionality



## Seeker (Apr 4, 2011)

I've came to an idea, to completely ditch *grep* in favor of *sed*.
Mainly because of this!

And especially, because I simply have a more power, at the hand, with sed.

To my horror, I've figured out that, sed returns exit code 0, upon *MATCH* and *NO_MATCH* (grep obeys these)
It will return 0>, only if it receives wrong regex or non existant file.

This makes me unable to use sed in i.e; bourne's 'if' statement

```
# Replaces 'grep -Eq ...' -> quiet
if eval "echo \"\$$container\"" | sed -En "/$sep$part$sep/q"; then
    echo 'I ALWAYS get executed'
else
    echo 'It is sed's fault, I NEVER get executed'
fi
```

I want to request devs, to *extend* sed's *exit codes functionality*, so it could differentiate between *MATCH* and *NO_MATCH*, or as sed has functions, which affects matching patterns:
*F_APPLIED* and *F_NOT_APPLIED*


----------



## gordon@ (Apr 4, 2011)

According to the Single Unix Specification (http://www.unix.org/single_unix_specification/), exit status for sed(1) is as follows:



> 0  -- Successful completion.
> >0 -- An error occurred.



Sed is a stream editor, not a matching program. That said, you could probably do the entire if block in sed, but that's an exercise for the reader.

I would fix your problems with grep.


----------

