---
# System prepended metadata

title: Bash scripting guide

---

# Bash scripting guide

This guide is meant to serve as a starting point for reading and understanding elements of Bash scripts.  

In general, shell scripting is a powerful way of automating tasks and "gluing" parts of programs together in a manner similar to how you type commands in a terminal.  Shell scripting has evolved over many decades and across many types of operating systems, shells, and programming goals.  This long history, and some semantic quirks of shells in general, can make shell scripting seem quite obtuse at first--indeed, there are a lot of exceptions, edges, and quirks to almost everything in shell scripting.  However, there are a few common principles that can help you understand how most shell scripts work and give you the tools you need to help figure out the rest as you need them!

This guide isn't intended to be comprehensive, but intends to give some examples of the most common script elements and some resources on where you can read more.  We focus specifically on scripting with bash--other shells may have slightly different semantics.

## Anatomy of a shell script

```shell!
#!/bin/bash   # <--- Interpreter line

something="hello world"      # A variable
all_files=$(find / -type f)  # A variable set from the output of a command

# This loop prints out a line for each file on the filesystem
for f in $all_files; do
    echo "This is a file:  $f"
done
```



