Skip to content

Use #!/usr/bin/env bash instead of #!/bin/bash #90

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

Merged
merged 1 commit into from
May 21, 2019

Conversation

jcoetzee
Copy link
Contributor

@jcoetzee jcoetzee commented Dec 11, 2018

macOS ships with an old version of bash that doesn't recognise declare -A. Using /usr/bin/env bash instead of referencing /bin/bash directly allows macOS users to use homebrew supplied bash instead of the built-in one.

macOS ships with an old version of bash that doesn't recognise `declare -A`. Using `/usr/bin/env bash` instead of referenceing `/bin/bash` directly allows macOS users to use homebrew supplied bash instead of the built-in one.
Copy link
Member

@karianna karianna left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What happens if that doesn't exist?

@jonpspri
Copy link

#!/usr/bin/env bash will run whichever bash is first in the path, which usually should not present a problem unless it's a really old bash. On the other hand, I wouldn't suggest putting bash 4-isms into the scripts unless we really need them. Most systems have at least bash 3.

@jcoetzee
Copy link
Contributor Author

Agreed that using Bash 4 features excludes macOS users from being able to build the images without some extra work. But then again Bash 4 is almost 10 years old now (released 20 Feb 2009) and it is possible for macOS users to install an up-to-date version. If you're building Docker on macOS then you probably have homebrew (or similar) installed already. There should just be some documentation around the requirement.

@karianna karianna requested a review from dinogun December 12, 2018 13:07
@karianna
Copy link
Member

Our policy for Adopt infra is to stick with Bash 3 because of the OS X reason. I think we'd at least want a documentation update if the docker images are going to support Bash 4

@jonpspri
Copy link

As a side note, I’m updating slim-java.sh to be compatible with bash or dash (thank heavens for ShellCheck), which should eliminate the need to apk-get bash in the Alpine images. The changes are done and tested. I just need to extricate them into a separate branch for a PR... likely within the next few hours.

@karianna
Copy link
Member

karianna commented Mar 5, 2019

@dinogun Not sure whether we should merge this or not - thoughts?

@grzesuav
Copy link
Contributor

grzesuav commented May 7, 2019

I would say it is more elegant way of running script - not to focus on specific binary.

From the other side - why not just require to install bash4 on mac ? It does not seems like big issue (https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)

@karianna karianna added this to the May 2019 milestone May 7, 2019
@karianna
Copy link
Member

I would say it is more elegant way of running script - not to focus on specific binary.

From the other side - why not just require to install bash4 on mac ? It does not seems like big issue (https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)

Mac OS X 10.10 doesn't support modern HomeBrew and I think it's difficult to therefore install bash4+

@jcoetzee
Copy link
Contributor Author

From the homebrew docs

10.12 or higher is recommended. 10.9–10.11 are supported on a best-effort basis.

Also Docker for Mac requires 10.12 anyway.

@jcoetzee
Copy link
Contributor Author

I would say it is more elegant way of running script - not to focus on specific binary.

From the other side - why not just require to install bash4 on mac ? It does not seems like big issue (https://itnext.io/upgrading-bash-on-macos-7138bd1066ba)

Maybe I'm misunderstanding you but that howto guide also installs bash4+ via homebrew which I what I did. Important to note that this won't replace the OS bundled one at /bin/bash but will install to /usr/local/bin/bash. This commit will need to be merged for homebrew installed bash to be referenced over OS bundled one.

@karianna
Copy link
Member

From the homebrew docs

10.12 or higher is recommended. 10.9–10.11 are supported on a best-effort basis.

Also Docker for Mac requires 10.12 anyway.

In that case we're probably OK to do this.

@gdams gdams merged commit f1ccb35 into AdoptOpenJDK:master May 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants