#!/bin/bash

# The shell parser does some processing over a command line.
# You need to quote strings to delimit them.

foo=hello, world    # This doesnt' work as intended. Why?

foo='hello, world'

# Quoting strings differently tells the shell how to process the string.
# The shell may perform some substitutions and manipulations of the string.
# This is called _expansions_ and is a very important concept in Bash and
# very different from the way variables are handled in other programming
# languages.
#
# There are three main quoting types:
#
# 1. Weak quoting (double quotes)
#    - Preserves the literal value of all characters within the quotes,
#      with the exception of $, `, \, and ! when history expansion is 
#      enabled.
#    - The $ character introduces parameter expansion, command substitution
#      and arithmetic expansion.

SOL=two
echo "the solution is $SOL"
echo "files in $PWD are: $(ls)"    # This is not a good idea, yet ...
echo "You can \"escape\" the double quote"

# One common use of weak quoting is to do _safe_ parameter expansion.
# Consider this example:
songfile="fake plastic trees.mp3"
rm $songfile                       # Does it work? Why?
rm "$songfile"                     # See the difference?

# 2. Strong quoting (single quotes)
#    - Preserves the literal value of all characters within the quotes.

echo 'Your home directory is $HOME'
echo 'You cannot \'escape\' the single quote''     # Why? Why the last '?

# 3. ANSI-C quoting
#   - Sequences of the from $'string' expands to string but treats
#     backslash-escaped characters in string as specified by the ANSI C
#     standard.
#   - Examples (see man pages for full list:
#       \a: alarm (bell)      \n: newline         \r: carriage return
#       \t: horizontal tab    \v: vertical tab    \cx: control-x character
#       \nnn: eight-bit character whose value is the octal value nnn
#       \xHH: eight-bit character whose value is the hex value HH

message=$'line one\vline two'
echo $message

