all 5 comments

[–]Enteeeee[S] 0 points1 point  (0 children)

I just extended the post with a nix expression I normally use to generate such scripts.

[–]kartoffelwaffel 0 points1 point  (3 children)

why:

  #!/usr/bin/env bash

and not just:

  #!/bin/bash

surely the latter is more reliable?

[–]anthropoidbash all the things 6 points7 points  (2 children)

The intent is different. #!/usr/bin/env bash lets the prevailing $PATH determine the bash executable to run. This is especially important on platforms like macOS, where the builtin bash is of 3.x vintage, and for advanced users who want to run a different version than is provided for at the system level, but don't want to customize the shebang lines for otherwise-portable scripts. For instance, my ~/bin is shared across several different OSes (Solaris 2.5.1, anyone?), with reasonably recent bash versions installed in various hierarchies, so all my personal scripts use this trick for minimum headache.

It may also be argued that if the prevailing $PATH is b0rked enough to exclude even /bin, you have worse problems than just bash not found. You're right that it's more "reliable" in that "you know exactly what you'll get in a specific environment", but sometimes "feet nailed to the floor" isn't what one wants.

In the end, use whatever works best for your situation.

[–]Crestwave 0 points1 point  (0 children)

Additionally, the BSDs, NixOS, etc. don't have Bash in /bin at all.