I would like like to terminate a script on any failure including inside a pipe. In bash, you can set -eo pipefail, but this doesn't work in ksh.


# x
set -eo pipefail
false | true
echo "done: $?" # reached in ksh, unexpected
echo "done2" # not reached in either shell, as expected
bash x        # prints nothing, as expected
ksh x         # done: 1
ksh --version # ... 93u+ 2012-08-01

Why would ksh not exit in this case?

Edit: Adding another test

I compared this to other shells and am getting different results:

-bash-5.0$ zsh -c 'set -eo pipefail; false | true; exit 2' ; echo $?
-bash-5.0$ ksh -c 'set -eo pipefail; false | true; exit 2'; echo $?
-bash-5.0$ bash -c 'set -eo pipefail; false | true; exit 2' ; echo $?

Other than a bug in ksh, I do not understand what could cause this behavior. According to man ksh:

-e    Unless contained in a ⎪⎪ or && command, or the command
      following an if while or until command or in the
      pipeline following !, if a command has a non-zero exit  # Pipeline does not follow !
      status, execute the ERR trap, if set, and exit.  This   # Pipeline has a non-zero exit status
      mode is disabled while reading profiles.

      A pipeline will not complete until all
      components of the pipeline have completed, and
      the return value will be the value of the last
      non-zero command to fail or zero if no command
      has failed.
  • 1
    You may use a questionable version of ksh93. It works as expected with the ksh93 t+ from 2010 from OpenSolaris and BTW: this is the fastest ksh93 ever seen.
    – schily
    Commented Apr 17, 2020 at 17:25
  • OpenBSD ksh93 u+ prints the done message, fwiw.
    – Shawn
    Commented Apr 17, 2020 at 20:43
  • @Shawn which is not surprising, since it's the same version as the OP's ;-)
    – user313992
    Commented Apr 18, 2020 at 6:41
  • I just tried on linux as well. Version ... 2020.0.0 has the same behavior. I will update the question with another test Commented Apr 18, 2020 at 20:35

1 Answer 1


It looks like a regression introduced by ksh93u+. ksh93u worked as expected in that regard (and like zsh, bash, mksh, yash and busybox sh).

I've just raised the issue at https://github.com/ksh93/ksh/issues/121

Now fixed in https://github.com/ksh93/ksh/commit/c049eec854d506ad6110eb50c769b10224c60075, included since v1.0.0-beta.1

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .