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
- Tell POSIX sh features apart from Bash-only features such as arrays and [[ ]]
- Choose the correct shebang, including #!/usr/bin/env bash, for the target system
- Rewrite a Bash script to run under dash using [ ] and case
- Check for required commands with command -v before using them
- Understand differences between GNU and BSD versions of tools like sed and date
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.
Other units in this stage
Back to the full Shell and Bash roadmap