AcademyThe Automator's Grimoire: Scripting WizardryCircle 1: Summoning Basics

Variables in Bash

Variables store data that you can use later in your script.

Rules of Variables

  1. NO SPACES around the equals sign!
    • Correct: NAME="Alice"
    • Incorrect: NAME = "Alice"
  2. Reference variables using the $ symbol.
#!/bin/bash
USER_NAME="Student"
echo "Welcome, $USER_NAME!"

Environmental Variables

You can export a variable to make it available to child processes (like other scripts or programs you run from this script).

export APP_ENV="production"
booting...

Mission Control

Declare a variable

Expected Command

cat vars.sh

Run the script