Show Menu
Cheatography

Bash Scripting Cheat Sheet (DRAFT) by

Set of scripting commands commonly used in bash scripts

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Introd­uction

This is a quick reference to getting started with Bash scripting.
Learn bash in y minutes (learn­xin­ymi­nut­es.com)
Bash Guide (mywik­i.w­ool­edg­e.org)
Bash Hackers Wiki (wiki.b­as­h-h­ack­ers.org)

String quotes

name="John"
echo "Hi $name"  #=> Hi John
echo 'Hi $name'  #=> Hi $name

Shell execution

echo "I'm in $(pwd)"
echo "I'm in 
pwd
" # obsolescent # Same

Functions

get_name() {
  echo "John"
}

echo "You are $(get_name)"

Strict mode

set -euo pipefail
IFS=$'\n\t'
 

Example

#!/usr/bin/env bash

name="John"
echo "Hello $name!"

Variables

name="John"
echo $name  # see below
echo "$name"
echo "${name}!"
Generally quote your variables unless they contain wildcards to expand or command fragments.