EasyEnv
Bash
Beginner

Bash

Learn Bash scripting from variables to robust, production-ready scripts. Loops, arrays, traps, set -euo pipefail, and a server bootstrap capstone.

12 lessons5.7h hands-on11 languages
Start learning freeBash course

12 lessons, in order

  1. 1

    What Is Bash

    Welcome. If you have never opened a terminal in your life, you are in the right place. Before we type a single command, we are going to spend ten...

    Shell vs terminalBash vs sh vs zshInteractive shell vs scriptWhere Bash fits in DevOps
    20 min
  2. 2

    Shebang and Your First Script

    If the word "script" still sounds like something only real programmers write, relax. A script is just a text file with a list of commands in it, and...

    Shebang#!/usr/bin/env bashChmod +x./script.sh vs bash script.shExit codes
    25 min
  3. 3

    Variables and Quoting

    If you have never used a variable before, do not worry. It is one of the simplest ideas in this whole course, and Bash's version of it is about as...

    Variable assignmentDouble quotes vs single quotes${var} bracesCommand substitution $(...)
    25 min
  4. 4

    Conditionals and Tests

    Every script you have written so far runs the same lines no matter what. Real scripts need to make decisions: "only do this if that file exists",...

    If statement[[ ]] testsString testsFile tests -f -d -e&& and ||Case statement
    30 min
  5. 5

    Loops

    So far every script you have written runs each line exactly once, top to bottom. That is fine for short scripts, but real work is repetitive: rename...

    For loopWhile loopUntil loopFor f in *.txt globbingC-style for loopBreak and continue
    25 min
  6. 6

    Functions

    By now your scripts are starting to repeat themselves. Maybe you log a timestamped message in three different places, or you check whether a file...

    Function definitionPositional args $1 $@ $#Return for exit codesEcho for outputLocal variables
    25 min
  7. 7

    Arrays

    So far, one variable has held one value. name="Ada" holds one string. If you wanted to hold three names, you would either need three separate...

    Indexed arrays${arr[@]}${#arr[@]} lengthAssociative arrays declare -AIterating arrays
    25 min
  8. 8

    String and Arithmetic Expansion

    You will constantly find yourself with a variable that holds almost, but not quite, what you need. A full file path when you only want the filename....

    ${var#prefix}${var%suffix}${var//old/new}$(( arith ))Printf formatting
    25 min
  9. 9

    IO Redirection and Pipes

    Every command you run in Bash is, underneath, hooked up to three separate channels, whether you ever notice them or not. Think of a mail sorting...

    >>><2>2>&1&>+3
    25 min
  10. 10

    Error Handling and Traps

    Every script you have written so far assumes things go right. A command that cannot find a file, a directory that does not exist, a typo in a...

    Set -eSet -uSet -o pipefailTrap on EXITTrap on ERRCleanup functions
    30 min
  11. 11

    Debugging and Best Practices

    At some point a script you wrote will do something you did not ask it to do. It will delete the wrong file, skip the loop you were sure it would run,...

    Bash -xSet -xShellcheckSafe quotingNever parse ls[[ vs [+1
    25 min
  12. 12

    Capstone: Server Bootstrap Script

    A brand new server is a machine with nothing on it. Somebody has to install the web server, create the account you will log in with, put your SSH key...

    Idempotent provisioningInstalling packagesCreating usersSSH key setupSystemd timersLogging+2
    60 min
Bash Course: Hands-on, in 11 Languages | Engineering Courses