24

The below mentioned line of code used to work for me all the time on a Ubuntu 16.04 distribution, but suddenly option-name pipefail is an illegal option:

set -eu -o pipefail

returns:

set: Illegal option -o pipefail

Why does this happen? I run the command on a completely new installed system and as part of a shell script. The code is placed right at the beginning:

myscript.sh:

1 #!/bin/bash
2 set -eu -o pipefail
3 ...

The script is run as sudo:

sudo sh ./myscript.sh
sunwarr10r
  • 4,420
  • 8
  • 54
  • 109
  • 3
    Possible duplicate of [Running bash script via Node.js - Illegal option -o pipefail](https://stackoverflow.com/questions/36730856/running-bash-script-via-node-js-illegal-option-o-pipefail) – l0b0 Jan 05 '19 at 19:44

2 Answers2

38

You are running bin/sh, on Ubuntu it is a symbolic link pointing to /bin/dash, but pipefail is a bashism.

Make the script executable:

chmod +x myscript.sh

and then run the script as follows:

sudo ./myscript.sh
sunwarr10r
  • 4,420
  • 8
  • 54
  • 109
l0b0
  • 55,365
  • 30
  • 138
  • 223
14

I had the same error when running script from zsh and the script began with incorrect shebang.

WRONG, missing ! after #:

#/bin/bash
rest-of-the-script

Correct:

#!/bin/bash
rest-of-the-script
Mike
  • 2,468
  • 3
  • 25
  • 36