Skip to content

Use /bin/bash in shebang for better cross-system compatibility#21

Merged
tatsumoto-ren merged 2 commits intoAjatt-Tools:mainfrom
Daja177:patch-1
Apr 20, 2026
Merged

Use /bin/bash in shebang for better cross-system compatibility#21
tatsumoto-ren merged 2 commits intoAjatt-Tools:mainfrom
Daja177:patch-1

Conversation

@Daja177
Copy link
Copy Markdown
Contributor

@Daja177 Daja177 commented Apr 20, 2026

Not all UNIX-based systems have Bash at /usr/bin/bash. On some Linux distributions and macOS, it may be located elsewhere (such as /bin/bash). Using /usr/bin/env bash lets the system find Bash via PATH, so the script runs more reliably across environments.

This change is also relevant to pull request #17, which aims to improve cross-platform compatibility (including environments where GNU tools or newer Bash versions may not be available by default).

@tatsumoto-ren
Copy link
Copy Markdown
Member

Hello! Yes, I don't know why we use /usr/bin/bash here. Luke Smith uses /bin/bash and /bin/sh instead.

I also use /bin/sh and /bin/bash in my dotfiles https://github.com/tatsumoto-ren/dotfiles/tree/main/.local/bin

@tatsumoto-ren tatsumoto-ren changed the title Use /usr/bin/env bash in shebang for better cross-system compatibility Use /bin/bash in shebang for better cross-system compatibility Apr 20, 2026
@tatsumoto-ren tatsumoto-ren merged commit 920dfe5 into Ajatt-Tools:main Apr 20, 2026
@Daja177
Copy link
Copy Markdown
Contributor Author

Daja177 commented Apr 20, 2026

Thanks, this is definitely an improvement 👍

One concern with #!/bin/bash though, it still hardcodes the path. On non-Linux UNIX systems where Bash isn't installed by default, it often ends up somewhere like /usr/local/bin (e.g. on FreeBSD), so it wouldn't be picked up there. The change in LukeSmithxyz/voidrice@2b5df86 makes sense for sh since /bin/sh is guaranteed, but that doesn't apply to Bash.

On macOS, /bin/bash is an older version incompatible with the current version of impd (this might change if #17 is accepted), so a newer Bash needs to be installed (e.g. via Homebrew in /opt/homebrew/bin), which wouldn't be used with #!/bin/bash.

Using #!/usr/bin/env bash lets the system pick the right Bash from PATH, which makes it work across more setups. Would you be open to that instead?

@tatsumoto-ren
Copy link
Copy Markdown
Member

tatsumoto-ren commented Apr 20, 2026

One concern with #!/bin/bash though, it still hardcodes the path. On non-Linux UNIX systems where Bash isn't installed by default, it often ends up somewhere like /usr/local/bin (e.g. on FreeBSD), so it wouldn't be picked up there. The change in LukeSmithxyz/voidrice@2b5df86 makes sense for sh since /bin/sh is guaranteed, but that doesn't apply to Bash.

I see. Do you think #!/usr/bin/env bash is better? The main argument against it is that it takes more time to execute because it needs to find where bash is.

On macOS, /bin/bash is an older version incompatible with the current version of impd (this might change if #17 is accepted), so a newer Bash needs to be installed (e.g. via Homebrew in /opt/homebrew/bin), which wouldn't be used with #!/bin/bash.

I think #17 can't be accepted as is because it removes some really handy bash-isms. I would rather try to find a way to run the latest version of GNU bash on macOS.

The question is, does /opt/homebrew/bin get added to the PATH? If not, #!/usr/bin/env bash would make no difference.

We could add this check to impd so it doesn't run on old Bash versions:

if [[ ${BASH_VERSION%%.*} -lt 5 ]]; then
      echo "Bash version is older than 5"
      exit 1
fi

@Daja177
Copy link
Copy Markdown
Contributor Author

Daja177 commented Apr 21, 2026

I ran a few benchmarks on my system, and the difference between #!/usr/bin/env bash and #!/bin/bash was only a few milliseconds at most per run, so it's negligible in this case.

The question is, does /opt/homebrew/bin get added to the PATH? If not, #!/usr/bin/env bash would make no difference.

On macOS, adding the Homebrew prefix to PATH is a required step for Homebrew to work. The installer explicitly tells users to update their shell config so the Homebrew prefix is added to PATH. As mentioned earlier, #!/usr/bin/env bash also helps on systems like FreeBSD where Bash is typically installed in /usr/local/bin.

The Bash version check you suggested is a good idea as long as impd continues to depend on Bash 5+ features.

tatsumoto-ren added a commit that referenced this pull request Apr 21, 2026
@Daja177 Daja177 deleted the patch-1 branch April 22, 2026 14:54
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.

2 participants