On macOS,
#!/bin/bash
means a script will use the system bash, which is very dated (3.2, 2006 year) and (for myself, at least) mostly useless.
Then you can install modern bash using Homebrew or MacPorts, and use something like this:
#!/usr/bin/env bash
[But the env
approach is not reliable: what if you run this script on a Mac where only the system bash is installed? Then, env
will use bash 3.2 instead (I suppose...), and this will make the script to misbehave and therefore can make harm.](https://unix.stackexchange.com/questions/29608/why-is-it-better-to-use-usr-bin-env-name-instead-of-path-to-name-as-my)
Then, the third approach is
#!/opt/homebrew/bin/bash
But what if you run this script on a Mac where modern bash is installed using MacPorts instead of Homebrew?
What is the best practice here? (Maybe create a symlink in /usr/local/bin
that points to /opt/homebrew/bin/bash
, and then #!/usr/local/bin
?)
Asked by jsx97
(1347 rep)
Mar 10, 2025, 06:01 PM
Last activity: Mar 11, 2025, 06:11 PM
Last activity: Mar 11, 2025, 06:11 PM