0

I have a file named test.sh:

#!/bin/bash -o pipefail
echo "Running test"
git diff HEAD^ HEAD -M --summary |
grep delete | 
cut --delimiter=' ' -f 5

When I try to run this script as:

./test.sh

I get:

/bin/bash: line 0: /bin/bash: ./test: invalid option name

I ran cat -v test.sh to check if there are carriage returns or anything, but that doesn't seem to be the case. I can run the script if I just run it as bash test.sh. Grateful for any help, and lmk if I can provide more info!

  • You can pass a single argument in the shebang, and you're trying to pass it two (-o and pipefail). I don't know of any system where that (still) works. – Uncle Billy Aug 1 '19 at 17:45
  • If this is linux, check your execve man page. – glenn jackman Aug 1 '19 at 17:47
2

The Linux kernel treats everything following the first “word” in the shebang line as a single argument. One solution is to set -o later in the script:

#!/bin/bash

set -o pipefail

echo "Running test"
git diff HEAD^ HEAD -M --summary | grep delete | cut --delimiter=' ' -f 5
| improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.