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

Make bash scripts more portable #347

Merged

Conversation

neutralinsomniac
Copy link
Contributor

Not every OS installs bash at /bin/bash. OpenBSD for instance installs bash at /usr/local/bin/bash. /usr/bin/env's location is defined by POSIX, so this will Always Work(R).

This makes ghidra run out-of-the-box on OpenBSD :)

@Crestwave
Copy link

/usr/bin/env's location is defined by POSIX, so this will Always Work(R).

Can you provide a source for this? As far as I know, POSIX does not define the location of any program. It's available there on most systems, though.

@neutralinsomniac
Copy link
Contributor Author

/usr/bin/env's location is defined by POSIX, so this will Always Work(R).

Can you provide a source for this? As far as I know, POSIX does not define the location of any program. It's available there on most systems, though.

Ah! You're right. It was Freedesktop I was thinking of, and it isn't so much that they defined a set path for env, but they merged /bin and /usr/bin: https://www.freedesktop.org/wiki/Software/systemd/TheCaseForTheUsrMerge/

My apologies. That said, though I can't find something to point to that says "env is always installed at /usr/bin/env", I can say I've never seen it installed anywhere else, and this form of calling out to env for shebangs in scripts is so widely adopted that it feels like an unofficial standard at the very least. :)

@ryanmkurtz ryanmkurtz self-requested a review April 5, 2019 18:04
@ryanmkurtz ryanmkurtz self-assigned this Apr 5, 2019
@ryanmkurtz ryanmkurtz added the Type: Enhancement New feature or request label Apr 5, 2019
@ljrk0
Copy link

ljrk0 commented Apr 9, 2019

For what it's worth, at least SunOS 5.10+ also has env(1) in /usr/bin. But it would be much more portable nonetheless, if simply ported to POSIX sh, since bash isn't installed everywhere.

@qbit
Copy link

qbit commented Apr 13, 2019

From POSIX:

Applications should note that the standard PATH to the shell cannot be assumed to be either /bin/sh or /usr/bin/sh, and should be determined by interrogation of the PATH returned by getconf PATH, ensuring that the returned pathname is an absolute pathname and not a shell built-in.

To my knowledge the only OS that has ‘env’ in a different location is GuixSD.

@ljrk0
Copy link

ljrk0 commented Apr 13, 2019

That's of course true, citing SunOS 5.10 again, /bin/sh is not a POSIX-compliant shell but the bourne-shell, just as /bin/ksh is the korn-shell, /bin/csh the c-shell etc., just as God intended ;)

But I think /bin/sh is a reasonable approximation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants