sd
sd copied to clipboard
sd returns exit code 0, even when there's no match
When sd
doesn't match an input, it should not return with exit code 0
this will cause issues when scripting.
echo 'target' | sd 'miss' 'hit' && echo $? target 0
Sorry, but I do not think it is a bug for me...
$ echo 'target' | sed 's/miss/hit/' && echo $?
target
0
sed
returns 0 as well because it does finish its task well.
People may want to easily know if nothing matched the pattern. At the very least it would be nice to add a flag that fails with a non-zero status if there was no match
More information: https://stackoverflow.com/a/15965681/13031497
Edit: Sorry about that I misunderstand. I also agree with a new flag.
I'm not sure where there's a disagreement. What you said matches my
At the very least it would be nice to add a flag that fails with a non-zero status if there was no match
I was thinking something along the lines of a --must-match
flag
Edit: Just to be clear I wasn't thinking of changing the default behavior. We should typically default to matching sed
's behavior which we do already here
Mark this as a feature request then, not a bug
I would like to second this. Just ran into an issue like this, and had to use oldschool sed
instead of sd
in my script because of how troublesome it is to detect whether any matches actually occurred.