Catalog / Dash Shell Scripting Cheatsheet
Dash Shell Scripting Cheatsheet
A concise cheat sheet for Dash shell scripting, covering essential syntax, commands, and best practices for writing efficient and portable shell scripts.
Dash Fundamentals
Basic Syntax
Comments |
|
Variables |
|
String literals |
|
Command Substitution |
|
Exit Status |
|
Shebang |
|
Control Structures
|
|
|
|
|
|
|
|
|
|
|
|
Commands and Utilities
File Manipulation
|
List directory contents |
|
Copy files or directories |
|
Move or rename files or directories |
|
Remove files or directories |
|
Create directories |
|
Create an empty file or update timestamp |
Text Processing
|
Display a line of text |
|
Concatenate and display files |
|
Search for a pattern in files |
|
Stream editor for text manipulation |
|
Pattern scanning and processing language |
|
Word, line, and byte count |
System Information
|
Print system information |
|
Print or set the system date and time |
|
Print working directory |
|
Print effective userid |
|
Show how long the system has been running |
|
Display amount of free and used memory |
Expressions and Operators
Arithmetic Operators
|
Addition |
|
Subtraction |
|
Multiplication |
|
Division |
|
Modulo |
|
Exponentiation (not POSIX standard, may not work on all shells) |
String Operators
|
Equality |
|
Inequality |
|
True if string is empty |
|
True if string is not empty |
File Test Operators
|
True if file exists |
|
True if file exists and is a regular file |
|
True if file exists and is a directory |
|
True if file exists and is readable |
|
True if file exists and is writable |
|
True if file exists and is executable |
Functions and Script Execution
Defining Functions
|
Example:
|
Passing Arguments to Functions
Accessing arguments |
|
All arguments |
|
Number of arguments |
|
Example |
|
Script Execution
Executing a script |
|
Making a script executable |
|
Sourcing a script |
|
Differences between executing and sourcing |
Executing runs in a subshell, sourcing runs in the current shell. |