Simple question, is the same ? Vim autocomplete me when write bash + tab => #!/usr/bin/env bash but I usually watch #!/bin/bash in every script. So..
- 185
1 Answers
TL;DR:
Use #!/usr/bin/env bash
Long answer:
Nope, they are not identical. The first form (#!/usr/bin/env bash) is better, as it will work when Bash is in your path, but isn't in /bin. Often, both will work. However, if your script runs on a system where /bin/bash isn't Bash (or isn't a symlink to it), then #!/bin/bash won't work as it isn't in that location, but #!/usr/bin/env bash will.
env looks up a command in your path, so if Bash is in your path but not in /bin, then you need to use env. Practically, because a decent amount of scripts don't use env, OS's tend to make /bin/bash either Bash or a symlink to it. Note that there is a small chance env won't work if you have using some old system, but on any reasonably modern OS (Debian, Ubuntu, Arch, Fedora, etc.) it is best to use env.
- 3,824