"set -e -o pipefail" not working on bash script on Ubuntu 16
Solution 1:
On Ubuntu the default shell is dash
(aka Debian Almquist Shell), to which /bin/sh
is symlink. When your shell script is run with #!/bin/sh
, you are effectively trying to run it with the default shell. However, dash
doesn't have the pipefail
option, which is why you're getting the error.
# Verifying what /bin/sh is symlinked to dash
$ ls -l /bin/sh
lrwxrwxrwx 1 root root 4 2月 17 2016 /bin/sh -> dash
# Verify that pipefail doesn't exist as option for dash
$ dash
$ set -o | grep pipefail
$ set -o pipefail
dash: 1: set: Illegal option -o pipefail
$ sh
$ set -o pipefail
sh: 1: set: Illegal option -o pipefail
# Try this same option in bash
$ bash --posix
bash-4.3$ set -o pipefail
bash-4.3$
# no error