0

i am currently having an issue with running a .sh file which can be found in here

https://github.com/grugslair/Rising-Revenant/blob/dev/contracts/scripts/default_auth.sh

i was originally dual booting windows and ubuntu 22.04 and i used to not get this error and the script worked fine so i know thats not an issue.

But for work reasons i have to now use WSL and now i cant seem to run it anymore i keep getting this

    alexhalo@Lappy:~/Rising-Revenant$ bash ./contracts/scripts/default_auth.sh
: invalid option nameefault_auth.sh: line 2: set: pipefail

I have asked in other places and they told me to run a couple of checks to see if everything was being used correctly and these are the outputs:

which bash
/usr/bin/bash

alexhalo@Lappy:~/Rising-Revenant$ bash --version
GNU bash, version 5.1.16(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2020 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law.


lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 22.04.3 LTS
Release:        22.04
Codename:       jammy

Was told to change the script to only use -eu and change pushd to cd... that didn't work

I have followed what this guys say here (How do I run .sh scripts?) to give executable permission but nothing

I have followed also this ("set -e -o pipefail" not working on bash script on Ubuntu 16) and tried to run every single line in the accepted answer and do get the same results as that person, but my script still doesn't run.

--edit: just for clarification on what I mean by running every single line i mean this

# 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

Also tried to disable dash as the default terminal (using sudo dpkg-reconfigure dash), so I would get bash but still get the error.

There is only this possible answer here ("set -eo pipefail" not working in Windows Subsystem for Linux (Ubuntu 16.04)) that i have not tried yet but to be honest i don't understand if the answer really is an answer or the guy is just making an example.

Any help would be appreciated :)

1 Answers1

1

Likely all you need to do is save the script with the correct (Unix-style) line endings.

If there was actually a problem with the option name, the error message would look like

./contracts/scripts/default_auth.sh: line 2: set: pipefail: invalid option name

However what you are seeing is

: invalid option nameefault_auth.sh: line 2: set: pipefail

That's because your script has been saved with Windows line endings, consisting of the two characters CR and LF, instead of the standard single character LF. So bash is parsing the command name as pipefail\r, (which it doesn't recognize as a valid option name) and the terminal sees

./contracts/scripts/default_auth.sh: line 2: set: pipefail

followed by a carriage return, then

: invalid option name

which overwrites the first part of the message, resulting in

: invalid option nameefault_auth.sh: line 2: set: pipefail

See also:

steeldriver
  • 136,215
  • 21
  • 243
  • 336