Cheat Sheet

Bash Shell Scripting Cheat Sheet

By Alex Soto Bueno
July 21, 2021
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

Cheat Sheet Excerpt

Print all elements from a plain array:

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

echo "Hello $i"



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

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

echo $key



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

echo $val


Want to see more? Get the full cheat sheet.

Tags: Linux Red Hat Enterprise Linux Cheat Sheet red hat linux bash shell Scripting Debugging monitoring