koalaman / shellcheck

ShellCheck, a static analysis tool for shell scripts
https://www.shellcheck.net
GNU General Public License v3.0
36.41k stars 1.78k forks source link

-x flag in docker container #1303

Open imjeremyhi opened 6 years ago

imjeremyhi commented 6 years ago

For bugs

For new checks and feature suggestions

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


#!/your/interpreter
# shellcheck disable=some/path
source "$(ENVPATH)"/path

Here's what shellcheck currently says:

After running shellcheck file.sh -x Does not return/exit

The issue is only reproducible with the -x flag within a docker container. It exits when path is invalid but hangs when the path is actually valid

Here's what I wanted or expected to see:

Should return/exit

koalaman commented 6 years ago

I interpreted this as you running shellcheck inside a docker container and getting a hang when following sourced files. I tried to reproduce this using the shellcheck-alpine image which has the latest git version of shellcheck as well as being a general purpose docker container with a shell and such.

However, it can't get it to hang with the commands and data given:

$ cat myfile
#!/your/interpreter
# shellcheck disable=some/path
source "$(ENVPATH)"/path

$ sudo docker run -i koalaman/shellcheck-alpine sh -c 'cat > file.sh; shellcheck file.sh -x' < myfile

In file.sh line 2:
# shellcheck disable=some/path
^-- SC1073: Couldn't parse this shellcheck directive. Fix to allow more checks.
                         ^-- SC1072: Expected '=' after directive key. Fix any mentioned problems and try again.

$

I also tried changing the invalid disable=some/path directive with source=file2.sh and creating that dependency, but it still doesn't hang:

$ cat myfile
#!/your/interpreter
# shellcheck source=file2.sh
source "$(ENVPATH)"/path

$ sudo docker run -i koalaman/shellcheck-alpine sh -c 'cat > file.sh; echo "hello" > file2.sh; shellcheck file.sh -x' < myfile

In file.sh line 1:
#!/your/interpreter
^-- SC1008: This shebang was unrecognized. Note that ShellCheck only handles sh/bash/dash/ksh.

$

Can you please expand on how to reproduce the issue?