Frequently Asked Question
Why use #!/usr/bin/env bash instead of #!/bin/bash?
#!/usr/bin/env bash asks the env program (which is reliably at /usr/bin/env on
every Unix) to search the PATH for the first executable named bash and run that.
#!/bin/bash hard-codes the location. On Linux distributions, bash is almost always at
/bin/bash, so both work. But on macOS the system bash is ancient (3.2, for licensing
reasons), and users typically install a modern bash via Homebrew at /usr/local/bin/bash
or /opt/homebrew/bin/bash; on FreeBSD, bash lives at /usr/local/bin/bash if installed
at all. The env form picks up whichever bash is first in the user's PATH.
The trade-off is that the env form is slightly less reproducible, it picks up whatever
bash the caller has, and slightly slower (one extra exec). For portable shell that must
run on any Unix, #!/usr/bin/env bash is the safer default; for distribution packages
that target Linux only and care about deterministic behaviour, #!/bin/bash is fine.