Skip to main content

Portability for Shell and Bashs

Portability is about writing shell scripts that behave the same across systems by knowing the difference between POSIX sh and Bash. Features like arrays, [[ ]] and process substitution are Bash extensions, while minimal systems such as Alpine's ash or Debian's dash may only support POSIX syntax. It is the last check before sharing a script.

Stage: Robust Scripts · Part of the Shell and Bash roadmap · Last reviewed 19 November 2026

What to learn in Portability

Portability interview questions

What is the difference between sh and bash?

sh refers to the POSIX shell standard, a small common feature set. Bash is a superset that adds arrays, [[ ]], brace expansion, process substitution and more. On some systems sh is a symlink to Bash, on others to dash, so Bash-only syntax can break.

Why use #!/usr/bin/env bash instead of #!/bin/bash?

The env form finds bash on the user's PATH, which helps on systems where Bash is not installed at /bin, for example macOS with a newer Homebrew version or some BSDs. The fixed path is more predictable and is often preferred for system scripts.

Where Portability fits in the Shell and Bash roadmap

Portability belongs to the Robust Scripts stage (beginner level), which takes about 9 hours. Reliability.

Back to the full Shell and Bash roadmap