Loading tool…
cheatsheet
name="value"Assign a variable (no spaces around =)
echo $namePrint a variable's value
readonly name="value"Declare a read-only variable
unset nameRemove a variable
if [ "$a" = "$b" ]; then ... fiBasic if statement (string equality)
if [ $a -eq $b ]; then ... fiNumeric equality comparison
if [ -f file.txt ]; then ... fiCheck if a file exists
if [ -d dir ]; then ... fiCheck if a directory exists
for i in 1 2 3; do echo $i; doneBasic for loop over a list
for f in *.txt; do echo $f; doneLoop over files matching a pattern
while [ $i -lt 10 ]; do ... doneWhile loop
function greet() { echo "Hello $1"; }Define a function taking one argument
greet "World"Call a function with an argument
return 0Return a status code from a function
#!/bin/bashShebang line - specifies the script interpreter
set -eExit immediately if any command fails
$1 $2 $#First arg, second arg, and total argument count
$?Exit status of the last command
Get new cheatsheets & tools in your inbox
No spam — just new releases, occasionally.