This is a draft cheat sheet. It is a work in progress and is not finished yet.
Introduction
This is a quick reference to getting started with Bash scripting. |
Learn bash in y minutes (learnxinyminutes.com) |
Bash Guide (mywiki.wooledge.org) |
Bash Hackers Wiki (wiki.bash-hackers.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.
|
|
|