Przejdลบ do treล›ci

๐Ÿง  Dash

Dash is a lightweight, fast, strictly POSIXโ€‘compliant shell used as /bin/sh on Debian and Ubuntu. It is optimized for speed, correctness, and minimalism, making it ideal for system scripts and automation.


๐ŸŽ“ Who This Is For

  • Engineers writing portable /bin/sh scripts
  • DevOps/SRE teams maintaining Debian/Ubuntu systems
  • CI/CD authors targeting minimal runners
  • Developers migrating bash scripts to POSIX sh

๐Ÿงฉ Role in the Ecosystem

  • Default /bin/sh on Debian and Ubuntu
  • Used for system startup scripts and maintenance tasks
  • Common in CI/CD environments based on Debian images
  • Acts as a portability validator (bashisms fail fast)

๐Ÿงฉ Key Characteristics

  • Very fast startup time
  • Strict POSIX compliance
  • Minimal feature set
  • No arrays, no [[ ]], no process substitution
  • Predictable behavior across environments

๐Ÿ”ง Notable Features

  • Pure POSIX test syntax:
1
2
3
if [ "$x" = "y" ]; then
  echo ok
fi
  • Efficient pipeline execution: Dash is significantly faster than bash for shortโ€‘lived scripts.

  • Lightweight function definitions:

1
2
3
myfunc() {
  echo "Hello from dash"
}

โš ๏ธ Limitations & Pitfalls

  • No bashโ€‘specific features (arrays, [[ ]], brace expansion, etc.)
  • No process substitution (<( ))
  • No associative arrays
  • Some GNU tools behave differently than expected
  • Bash scripts often break silently when run under dash

๐Ÿง  When to Use Dash

  • System scripts intended for /bin/sh
  • CI/CD pipelines requiring speed and portability
  • Automation on Debian/Ubuntu systems
  • Scripts that must run in minimal environments

โŒ When Not to Use Dash

  • Scripts requiring bash extensions
  • Complex logic involving arrays or advanced pattern matching
  • Interactive workflows (bash/zsh are better)

โœ… Best Practices

  • Use #!/bin/sh for POSIX scripts
  • Test explicitly under dash:
1
dash script.sh
  • Avoid bashisms ([[ ]], arrays, ${var//pattern/repl})
  • Keep scripts simple and predictable
  • Validate portability using dash as the reference shell

๐Ÿงช Testing Dash Scripts

1
2
dash -n script.sh        # syntax check
set -x                   # basic tracing

๐Ÿง  Summary

Dash is the fast, strict, POSIXโ€‘compliant /bin/sh used on Debian and Ubuntu. If your script runs correctly under dash, it is portable, predictable, and suitable for production automation.