LinuxCommandLibrary

dash

Execute shell scripts

TLDR

Start an interactive shell session

$ dash
copy

Execute specific [c]ommands
$ dash -c "[echo 'dash is executed']"
copy

Execute a specific script
$ dash [path/to/script.sh]
copy

Check a specific script for syntax errors
$ dash -n [path/to/script.sh]
copy

Execute a specific script while printing each command before executing it
$ dash -x [path/to/script.sh]
copy

Execute a specific script and stop at the first [e]rror
$ dash -e [path/to/script.sh]
copy

Execute specific commands from stdin
$ [echo "echo 'dash is executed'"] | dash
copy

SYNOPSIS

dash [-aceEfinopstvx] [-o option] [command [arg ...]]
dash [-acEefinopstvx] [-o option] [-] [argument ...]

PARAMETERS

-a
    Export all declared variables to the environment

-c
    Read commands from the following string argument

-e or -o errexit
    Exit immediately if a command exits with nonzero status

-E
    Enable error checking for undefined variables

-f or -o noglob
    Disable pathname expansion

-i
    Force shell to be interactive

-n
    Syntax check only; do not execute commands

-o option
    Set shell option by name (e.g., errexit, noclobber)

-p
    Use $PATH, $HOME, $SHELL, $ENV, $PWD from environment

-s or -
    Read commands from standard input

-t or -o oneword
    Exit after reading and executing one command

-v or -o verbose
    Echo input commands

-x or -o xtrace
    Print commands and arguments as executed

DESCRIPTION

Dash, the Debian Almquist Shell, is a compact and fast implementation of the POSIX sh shell. Designed as a drop-in replacement for traditional Bourne shell, it serves as /bin/sh in Debian-based distributions like Ubuntu. Dash prioritizes speed and standards compliance over feature-rich scripting, making it ideal for system initialization scripts (init, rc) where performance matters.

Unlike Bash, Dash lacks advanced extensions like arrays or brace expansion, enforcing stricter POSIX semantics. This ensures portability but may require script adjustments. Its minimal footprint (around 100KB) conserves memory in resource-constrained environments. Dash supports job control, command-line editing (via libedit), and common shell features while parsing scripts faster than Bash—up to 4x in benchmarks.

Primarily invoked indirectly via #!/bin/sh shebangs, Dash excels in non-interactive use, enhancing boot times and script execution efficiency.

CAVEATS

Not Bash-compatible; lacks arrays, process substitution, brace expansion.
Stricter POSIX adherence may break non-portable scripts.
Interactive mode has basic editing (Emacs/Vi keys via libedit).

INVOCATION MODES

Without args: interactive shell.
With -c string: execute string as script.
With file args: run script with positional params.
As login shell (--login): source /etc/profile.

PERFORMANCE NOTE

Dash parses/executes traditional shell scripts 3-5x faster than Bash, ideal for /etc/init.d and Debian Policy-compliant shebangs.

HISTORY

Originated from NetBSD's ash by Kenneth Almquist (1989-1990s). Herbert Xu enhanced it for Debian (2002); adopted as /bin/sh in Debian 4.0 (2006) to boost boot speed. Actively maintained, with POSIX 2008 compliance.

SEE ALSO

sh(1), bash(1), ksh(1), zsh(1)

Copied to clipboard