DangKit
All Cheatsheets

Bash Cheat Sheet

# Bash Cheat Sheet ## Variables ```bash NAME="value" # No spaces around = echo $NAME # Use $ to access echo ${NAME:-default} # Default if unset ``` ## Conditionals ```bash if [ "$a" = "$b" ]; then echo "equal" elif [ "$a" -gt "$b" ]; then echo "greater" else echo "other" fi ``` ## Loops ```bash for i in 1 2 3; do echo $i; done for f in *.txt; do echo "$f"; done while read line; do echo "$line"; done < file ``` ## Functions ```bash greet() { echo "Hello, $1" } greet "World" ``` ## Pipes & Redirection ```bash cmd1 | cmd2 # Pipe output cmd > file # Redirect stdout cmd >> file # Append cmd 2>&1 # Redirect stderr cmd < file # Redirect stdin ```
DangKit โ€” 139+ Free Online Tools: PDF, Dev, Design, Finance & More