Skip to main content
edited tags
Link
Gilles 'SO- stop being evil'
  • 866.1k
  • 205
  • 1.8k
  • 2.3k
Source Link

Pass through exit status code after using ||

I want to write an alias that's something like:

alias baz="false || echo bar"

(It's not actually false, it's a command that can fail). However, I want to pass the failed status code through to the next invoker. In other words, here's the current behavior:

$ false; echo $?
1
$ false || echo foo; echo $?
0

I want to do a different operation that has the same behavior in every respect as false || echo foo, except when I do echo $? it would return 1.

Note: I expect the echo foo bit to essentially always succeed.