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

Feature: detect nonportable shebangs #1047

Open
2 tasks done
asomers opened this issue Nov 13, 2017 · 4 comments
Open
2 tasks done

Feature: detect nonportable shebangs #1047

asomers opened this issue Nov 13, 2017 · 4 comments

Comments

@asomers
Copy link

asomers commented Nov 13, 2017

A very common cause of shell script portability problems is an assumption that the interpreter lives at a certain location. For example, Linux users often hardcode "#!/bin/bash", but bash is typically installed to "#!/usr/local/bin/bash" on BSD systems. Portable scripts should therefore use "#!/bin/sh" or "#!/usr/bin/env " instead.

For new checks and feature suggestions

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

#!/bin/bash
echo "Hello World!"

Here's what shellcheck currently says:

Here's what I wanted or expected to see:

^-- SCXXXX: "/bin/bash" is nonportable. Prefer "/usr/bin/env/bash"

@Nightfirecat
Copy link
Contributor

Duplicate of #112 and #880. I'd advise reading the comments on each of those issues to understand why that is likely not a good idea.

@asomers
Copy link
Author

asomers commented Nov 13, 2017

Sorry I couldn't find those earlier issues. I understand their objections, but all of those objections only apply to scripts whose exact target environment is known. For example, scripts residing in a package built for a particular OS. ShellCheck is mostly useful further upstream, for software that hasn't yet been packaged. In such cases, the only appropriate shebang is a portable one or a blank one (to be added by the Makefile).

@arth1
Copy link

arth1 commented Jan 12, 2018

But it is not portable. It relies on (1) /usr/bin/env being present, and (2) that the shell interpreter of choice is in the PATH. Neither is a given.
From an AIX machine here:

$ which bash
which: 0652-141 There is no bash in /usr/bin /usr/local/bin /etc /usr/sbin /usr/ucb /usr/binX11 /sbin ..

On this machine, #!/opt/freeware/bin/bash would be the correct shebang, and a warning that this is better done with env would not be helpful.

Another machine has /usr mounted by NFS. Until it is mounted, /usr/bin is not available, so /usr/bin/env cannot be called. Replacing the startup scripts to use /usr/bin/env based on a shellcheck recommendation to do so would render the system unbootable.

Anyhow, the security risk of using env noted in #880 should trump any other concerns here, IMNSHO.

@Gandalf-
Copy link
Contributor

Gandalf- commented Jan 1, 2019

Should this issue be closed as invalid?

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