Cheat Sheet

Bash Shell Scripting Cheat Sheet

Alex Soto Bueno
July 21, 2021
Bash Shell Scripting Cheat Sheet Cover

About

Red Hat UBI book cover

Bash is a command language interpreter: a version of the classic Unix shell with many enhancements. Bash is the default shell installed on GNU/Linux distributions and many other Unix-style systems, such as macOS.

Although most developers have a working knowledge of Bash for everyday interactive use, few know the rich features it offers for writing scripts. It supports most of the statements that other languages provide, such as indexed and associative arrays, foreground/background task execution, pipes, redirections, loops, functions, and Boolean expressions.

In this cheat sheet you will learn how to:

  • Create Bash scripts
  • Manipulate strings
  • Create credentials
  • Control script flow with conditionals and loops
  • Use collections

Excerpt

Print all elements from a plain array:

for i in "${names[@]}"; do

echo "Hello $i"

done

 

Print keys and values of all elements from a key/value array:

for key in "${!score[@]}"; do

echo $key

done

 

for val in "${score[@]}"; do

echo $val

done

Comments