Skip to content

Use /usr/bin/env bash shebang in shell scripts #25934

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

Closed
wants to merge 4 commits into from

Conversation

boltzmannrain
Copy link
Contributor

@boltzmannrain boltzmannrain commented Apr 23, 2025

#!/usr/bin/env bash is more portable than #!/bin/bash because it can pick up Bash from more locations and is also customizable via PATH. Some scripts were already using #!/usr/bin/env bash but not all.

Note: only touching plain shell script files in this PR, script
files that are generated in rules are also subject to same
portability concern but change there may need extra attention

Edge cases:

  • replacing arguments with set commands as it isn't universally supported to combine env+cmd+args. So /bin/bash -eu -> /usr/bin/env bash; set -eu
  • src/test/shell/bazel/bazel_wrapper_test.sh sets up mock bin/ location, adding bash there to be picked up is needed, for now not doing that and excluding scripts/packages/bazel.sh from changes

`#!/bin/bash` is less portable than `#!/usr/bin/env bash` because it can
pick up Bash from more locations and is also customizable via `PATH`.
Some scripts were already using `#!/usr/bin/env bash` but not all.

Note: only touching plain shell script files in this PR, script
      files that are generated in rules are also subject to same
      portability concern but change there may need extra attention
@github-actions github-actions bot added team-Rules-Java Issues for Java rules team-Remote-Exec Issues and PRs for the Execution (Remote) team awaiting-review PR is awaiting review from an assigned reviewer labels Apr 23, 2025
@allevato allevato removed their request for review April 23, 2025 19:21
@thomasvl thomasvl removed their request for review April 23, 2025 19:22
@meisterT meisterT added team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website and removed team-Rules-Java Issues for Java rules team-Remote-Exec Issues and PRs for the Execution (Remote) team labels May 7, 2025
@meisterT meisterT requested a review from meteorcloudy May 7, 2025 11:38
Copy link
Member

@meteorcloudy meteorcloudy left a comment

Choose a reason for hiding this comment

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

Thanks!

@meteorcloudy meteorcloudy added awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally and removed awaiting-review PR is awaiting review from an assigned reviewer labels May 7, 2025
@copybara-service copybara-service bot closed this in 11717a1 May 8, 2025
@github-actions github-actions bot removed the awaiting-PR-merge PR has been approved by a reviewer and is ready to be merge internally label May 8, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
team-OSS Issues for the Bazel OSS team: installation, release processBazel packaging, website
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants