Sh

Working notes on Sh: Call a script, case, case example, Command-line arguments, Function, and If else, and related topics.

Topics

Call a script

Run a shell script with sh and optional positional arguments.

case

Shell case syntax matching values and running the matching statement.

case example

A case branch on TEST, including a default * pattern.

Command-line arguments

Positional parameters in a shell script, indexed from 1.

Function

Define a shell function, refer to $1 arguments, and call it. POSIX function keyword on dash.

If else

Shell if, elif, and else syntax, with numerical and string comparison operators.

Include

Source another shell file with . (alias for source).

Inline

Inline a command's output in a string with $(...).

Output to file and screen

Send stdout and stderr to both the screen and a file with tee -a.

Shebang

Portable bash shebang using env, and why sh is not bash.

String

Single quotes block variable expansion unless they sit inside double quotes.

Updated: 2026 Aug 19