#!/bin/bash

# Variables do not have to be declared before they are used.
# If you try to read an undeclared variable, the result is the empty
# string.
echo $my_var

# This can be a source of errors like typos in variable names that lead
# to silent failures.
# Using the set -u (or set -o nounset) options changes this behavior.

# Without set -u.
echo "hello, $name"

# With set -u.
set -u
echo "hello, $name"

# You can remove (destoy) a variable with unset.
# This is different from assigning the empty string to the variable.
# unset removes the variable from the list of variables.
# Useful for memory management, controlled scope, and error prevention.
my_var=foo
echo $my_var   # output: foo

unset my_var

echo $my_var    # output (nothing) or error if set -u option is set

# SPOILER: unset can also remove function declarations (functions are
# symbols, too).
