Skip to content

Use "#!/usr/bin/env bash" shebang in all shell scripts - #1426

Closed
rjeffman wants to merge 1 commit into
freeipa:masterfrom
rjeffman:hashbang
Closed

Use "#!/usr/bin/env bash" shebang in all shell scripts#1426
rjeffman wants to merge 1 commit into
freeipa:masterfrom
rjeffman:hashbang

Conversation

@rjeffman

@rjeffman rjeffman commented Jul 9, 2026

Copy link
Copy Markdown
Member

Replace hardcoded "#!/bin/bash" with "#!/usr/bin/env bash" across all shell scripts in infra/, tests/, and utils/ to improve portability on systems where bash is not at /bin/bash (e.g., macOS with Homebrew bash).

Summary by Sourcery

Enhancements:

  • Replace hardcoded /bin/bash shebangs with /usr/bin/env bash in infra, tests, and utils shell scripts to support systems where bash is not installed in /bin.

@rjeffman
rjeffman requested a review from t-woerner July 9, 2026 18:21

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Hey - I've found 2 issues

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location path="infra/image/build.sh" line_range="1" />
<code_context>
-#!/bin/bash -eu
+#!/usr/bin/env bash -eu
 # This file shoud be source'd (. set_test_modules) rather than executed.
 #
</code_context>
<issue_to_address>
**issue (bug_risk):** Using `env` in the shebang with options changes how arguments are passed and may break `-eu` handling.

On most systems, `#!/usr/bin/env bash -eu` will treat `/usr/bin/env` as the interpreter and pass `'bash -eu'` as a single argument, so `env` won’t split out `-eu` as options to `bash`. That means the script may run without `-eu` or fail, depending on the platform. To keep portability and strict flags, use `#!/usr/bin/env bash` and add `set -eu` in the script body, or revert to `#!/bin/bash -eu` if you rely on the shebang for `-eu`.
</issue_to_address>

### Comment 2
<location path="infra/image/system-service/fixipaip.sh" line_range="1" />
<code_context>
-#!/bin/bash -eu
+#!/usr/bin/env bash -eu
 # This file shoud be source'd (. set_test_modules) rather than executed.
 #
</code_context>
<issue_to_address>
**issue (bug_risk):** Shebang change here has the same `env` + options concern and may affect script behavior.

This change makes the script rely on `/usr/bin/env` correctly handling `bash -eu` as separate arguments, which is not portable and may change exit/error behavior. Please switch to a safer pattern such as `#!/usr/bin/env bash` with `set -eu` inside the script, or keep `#!/bin/bash -eu` if `/bin/bash` is guaranteed in your environments, and apply the same approach to the other updated scripts.
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment thread infra/image/build.sh Outdated
Comment thread infra/image/system-service/fixipaip.sh Outdated
@rjeffman
rjeffman force-pushed the hashbang branch 5 times, most recently from e3991d1 to cf4b0df Compare July 10, 2026 00:57
Replace hardcoded "#!/bin/bash" with "#!/usr/bin/env bash" across all
shell scripts in infra/, tests/, and utils/ to improve portability on
systems where bash is not at /bin/bash (e.g., macOS with Homebrew bash).

Signed-off-by: Rafael Guterres Jeffman <rjeffman@redhat.com>
@rjeffman

Copy link
Copy Markdown
Member Author

Closing as we can't actually use this solution.

@rjeffman rjeffman closed this Jul 15, 2026
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

Successfully merging this pull request may close these issues.

1 participant