Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sd returns exit code 0, even when there's no match #157

Open
iiiraq opened this issue May 23, 2022 · 6 comments
Open

sd returns exit code 0, even when there's no match #157

iiiraq opened this issue May 23, 2022 · 6 comments
Assignees
Labels
C-enhancement Category: New feature or request

Comments

@iiiraq
Copy link

iiiraq commented May 23, 2022

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

@CosmicHorrorDev CosmicHorrorDev self-assigned this May 12, 2023
@CosmicHorrorDev CosmicHorrorDev added C-bug Category: Something isn't working M-needs triage Meta: Maintainer label me! labels May 17, 2023
@CosmicHorrorDev CosmicHorrorDev added this to the v0.8.0 Release milestone May 17, 2023
@PeterlitsZo
Copy link

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.

@CosmicHorrorDev
Copy link
Collaborator

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

@PeterlitsZo
Copy link

PeterlitsZo commented Jun 13, 2023

More information: https://stackoverflow.com/a/15965681/13031497

Edit: Sorry about that I misunderstand. I also agree with a new flag.

@CosmicHorrorDev
Copy link
Collaborator

CosmicHorrorDev commented Jun 13, 2023

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

@dev-ardi
Copy link
Contributor

Mark this as a feature request then, not a bug

@CosmicHorrorDev CosmicHorrorDev added C-enhancement Category: New feature or request and removed C-bug Category: Something isn't working M-needs triage Meta: Maintainer label me! labels Oct 20, 2023
@crabdancing
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-enhancement Category: New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants