4.2 Accessing data stored in variables

Before executing a command BASH is replacing all variables with its content. To indicate a string as a variable, put the character $ in front and use { and } to avoid ambiguity.

echo $b
#Hello world
echo "Dan says: $b"
#Dan says: Hello world
echo "D${a}n"
#D10n
$a  
#10: command not found

In the last case, $a will be replaced with 10, which will then be executed, resulting in the error that the command 10 does not exist.

Now it is time to revisit the issues with single vs double quotes. The difference between them is thta BASH only expands strings put in double quotes, but not single quotes.

echo "Dan says: $b"
Dan says: 
echo 'Dan says: $b'
Dan says: $b

So often putting things in single quotes saves a lot of escaping.