Skip to content

Instantly share code, notes, and snippets.

@justinmklam
Last active September 20, 2019 18:03
Show Gist options
  • Save justinmklam/73045032e6296bc732c4d2a941658051 to your computer and use it in GitHub Desktop.
Save justinmklam/73045032e6296bc732c4d2a941658051 to your computer and use it in GitHub Desktop.
Common shebangs for shell scripts.

Bash

For POSIX (ie. not just Linux):

#!/bin/sh.

For GNU bash:

#!/bin/bash

or

#!/usr/bin/env bash

Note: Use the latter if the following scenario applies:

#!/usr/bin/env searches PATH for bash, and bash is not always in /bin, particularly on non-Linux systems. For example, on my OpenBSD system, it's in /usr/local/bin, since it was installed as an optional package.

If you are absolutely sure bash is in /bin and will always be, there's no harm in putting it directly in your shebang—but I'd recommend against it because scripts and programs all have lives beyond what we initially believe they will have.

Source: https://stackoverflow.com/a/21613044

Python

For python. Source: https://stackoverflow.com/a/19305076

#!/usr/bin/env python3
# -*- coding: utf-8 -*-

For python 2 and 3; rare case where compatibility with both versions is required.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment