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

(grcat) exit code zero despite previous pipe command returning non-zero #53

Open
sarnobat opened this issue Feb 13, 2017 · 5 comments
Open

Comments

@sarnobat
Copy link

sarnobat commented Feb 13, 2017

(I know grcat isn't meant for public use but like i said in another ticket it's really convenient; if this is unsupported I'm just putting this ticket out there in case grcat becomes supported)

When I run:

mvn compile | grcat ~/conf.mvn

and the compilation fails, I get exit code zero. This makes it a bit difficult to run a script that checks whether the compilation succeeded before running the next command. For example, I often run this:

mvn compile | grcat ~/conf.mvn && sh deploy_my_app.sh

and when deploy_my_app.sh prints loads of stuff and I'm not looking at my screen I don't see the failed mvn command, so start tearing my hair out wondering my my app isn't working.

@richarson
Copy link
Contributor

As a workaround, you can use $PIPESTATUS:

$ true | grcat ../.grc/conf.ping ; echo $PIPESTATUS
0
$ false | grcat ../.grc/conf.ping ; echo $PIPESTATUS
1

E.g.:

mvn compile | grcat ~/conf.mvn
[ $PIPESTATUS -eq 0 ] && sh deploy_my_app.sh

@sarnobat
Copy link
Author

Thanks for the suggestion. Feel free to close the ticket.

@garabik
Copy link
Owner

garabik commented Feb 14, 2017

This is actually a valid concern - however, note that cat would eat the exit status too, so it is a matter of how much compatibility with cat we want to maintain.

In addition to $PIPESTATUS, you might use set -o pipefail if your shell is bash.

@sarnobat
Copy link
Author

sarnobat commented Mar 3, 2017

Pipefail also works in zsh 5.0.8, thankfully for me.

foobar | cat && echo "Succeeded wrongly"
zsh: command not found: foobar
Succeeded wrongly


set -o pipefail; foobar | cat || echo "failed correctly"
zsh: command not found: foobar
failed correctly

@jnovack
Copy link
Contributor

jnovack commented Jun 10, 2020

I would suggest you maintain 100% compatibility with cat (well, minus the colourizing 👀).

In this manner, it's a drop-in replacement and scripts do not need to be reconfigured.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants