Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

set -euo pipefail no longer works with latest shellcheck-alpine docker image #1489

Closed
1 task done
monemihir opened this issue Feb 11, 2019 · 6 comments
Closed
1 task done

Comments

@monemihir
Copy link

monemihir commented Feb 11, 2019

For bugs

  • SC2039
  • koalaman/shellcheck-alpine:latest (released 2 days ago as of writing this issue). The previous version of the container as of writing this issue = v0.6.0
  • The rule's wiki page does not already cover this
  • I tried on shellcheck.net but it works on the website. Most likely to do only with the docker container
  • I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related

This was working until a few days ago but has suddenly started to give this error. If we go back and try the same script with v0.6.0 it works as expected.

Here's a snippet or screenshot that shows the problem:

#!/usr/bin/env sh
# shellcheck disable=SC2044
set -euo pipefail

rc=0
for filename in $(find . -name '*.sh') ; do
  echo "==> Validating ${filename}"
  shellcheck "${filename}" || exit $?
done

exit $rc

Here's what shellcheck currently says:

In ./tests/scripts/validate_shell_scripts.sh line 3:
--
set -euo pipefail
         ^------^ SC2039: In POSIX sh, set option pipefail is undefined.
 
For more information:
https://www.shellcheck.net/wiki/SC2039 -- In POSIX sh, set option pipefail ...

Here's what I wanted or expected to see:

No issues detected

@Quasic
Copy link

Quasic commented Feb 11, 2019

I wonder if something happened with #1480

@koalaman
Copy link
Owner

ShellCheck is correct. pipefail is not a valid shell options for sh scripts. Here's what happens if you try to run your script on Debian based distributions:

$ ./test.sh
./test.sh: 3: set: Illegal option -o pipefail

Your script does not do anything that warrants setting the pipefail option, so you can consider just removing it. If you want to keep it, set the shebang to a shell that supports pipefail such as bash or ksh.

@monemihir
Copy link
Author

Can you please tell me the syntax for the shebang for bash? Or what is the path for it in the container?

I have tried the following:

#!/usr/bin/env bash
#!/bin/bash
#!bash

However all of them give on of the following errors:

standard_init_linux.go:190: exec user process caused "no such file or directory"
env: can't execute 'bash': No such file or directory

@koalaman
Copy link
Owner

Oh, you want to both check and run the scripts inside the alpine-linux container.

Are these scripts intended to ever be runnable outside alpine-linux? If so, the best way may be to install Bash with apk add bash and explicitly depend on that with #!/usr/bin/env bash

If you don't need them to be runnable outside alpine-linux, you can ignore the issue with a comment saying that you already know that sh will be BusyBox's Ash, so it will support pipefail.

Optimally you would just have used #!/usr/bin/env ash, but ShellCheck does not support Ash and will emit warnings saying that, so this is likely not a very pragmatic solution.

@monemihir
Copy link
Author

I am using this container like so:

docker-compose run --rm shellcheck sample.sh

The docker-compose file:

---
version: '2.0'
services:
  shellcheck:
    image: koalaman/shellcheck-alpine:latest
    volumes:
      - ".:/build"
    working_dir: /build

Is there anyway I can install bash on the fly and run shellcheck? Unfortunately creating a new container and then using that is not an option for me.

I have tried updating the compose file to override the command but haven't found a working solution.

command: /bin/sh -c "apk add bash" && /bin/shellcheck
command: apk add bash && /bin/shellcheck
entrypoint: /bin/sh -c
command: /bin/sh -c "apk add bash" && /bin/shellcheck
entrypoint: /bin/sh -c

No matter what I do, I keep getting this error:

ERROR: Cannot start service shellcheck: OCI runtime create failed: container_linux.go:348: starting container process caused "exec: \"sample.sh\": executable file not found in $PATH": unknown

@nrxr
Copy link

nrxr commented Aug 22, 2019

That error is telling you it can't find sample.sh. Did you copy it? It's on the working directory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants