#!/bin/bash

# When you run a script from an interactive shell, it executes in a
# child process (a subshell) unless you use the 'source' command.
# When the subshell is created, it inherits a copy of its parent
# environment.
# Use 'env' or 'printenv' to list the environment of the current shell:
env  # Also printenv

# If you want a subshell to inherit a variable, you need to export it to
# the environment.
my_var=foo
export my_var  
export my_var2=bar  # declaration & export

# Exercise:
#   - Test the export command with a simple script that prints a variable.
#   - Test it when you "source" the script.

# IMPORTANT:
# Do not mistake the environment for the command execution environment:
# Executed commands inherit the environment.
#
# The 'env' command can be used to set the environment passed to a command.
# Try it!
#   $ env FOO=bar ./echofoo.sh
#
# This is very useful and is sometimes used as the interpreter on the first
# line of the script.
# See the env and execve man pages for more details.
