sh is the standard Unix shell since Version 7 Unix. POSIX has standardized shell behavior based on the Bourne Shell, and portable shell scripts should conform to the standardized syntax. Use this tag for questions that apply to Bourne/POSIX-style shells. For shell scripts with errors, please check them in http://shellcheck.net before posting here.
sh, aka the Bourne Shell, is the standard Unix shell since v7 Unix, in standard location /bin/sh
.
POSIX has since standardized shell behavior based on the Bourne Shell, and portable shell scripts should conform to the standardized syntax.
The most common successor to the Bourne Shell (sh) is bash - The Bourne-Again SHell and many Unix-like operating systems have /bin/sh
linked to the bash
executable; when bash
is called as sh
, it runs in a (mostly) POSIX-compliant mode.
The Stack Overflow bash tag wiki has a large FAQ section; many of the questions and answers there also pertain to (many variants of) sh
.
The dash-shell (Debian Almquist shell) is also used as a small and fast POSIX-compliant shell for running shell scripts; Debian and Ubuntu systems have /bin/sh
linked to the dash
executable.
Tools
checkbashisms
(from thedevscripts
package) is a useful tool for ensuring that a shell script is POSIX-compliant and does not use features not specified by POSIX.ShellCheck is a web application that analyses shell scripts and checks for common mistakes (both syntax and semantic errors) as well as compliance with the POSIX standard, e.g., it highlights unquoted variables and Bashisms (if
sh
is used in the shebang). It can also be installed as an off-line command-line tool; see the repository in GitHub for more information.