What is the preferred Bash shebang ("#!")?

bash, shebang

Solution

You should use `#!/usr/bin/env bash` for portability: Different *nixes put `bash` in different places, and using `/usr/bin/env` is a workaround to run the first `bash` found on the `PATH`.

And `sh` is not `bash`.

Problem

Is there any `Bash` shebang objectively better than the others for most uses? - `#!/usr/bin/env bash` - `#!/bin/bash` - `#!/bin/sh` - `#!/bin/sh -` - etc I vaguely recall a long time ago hearing that adding a dash to the end prevents someone passing a command to your script, but can’t find any details on that.

Original source

Related problems