variable=This string is the value of the variable
echo $variable
bash: line 1: string: command not found
Marie-Hélène Burle
Let’s experiment with quotes:
bash: line 1: string: command not found
Oops…
This string is the value of the variable
This string is the value of the variable
bash: -c: line 1: unexpected EOF while looking for matching `''
Oops…
One solution to this is to use double quotes:
This string's the value of the variable
Alternatively, single quotes can be escaped:
This string's the value of the variable
Admittedly, this last one is a little crazy. It is the way to escape single quotes in single-quoted strings.
The first '
ends the first string, both "
create a double-quoted string with '
(escaped) in it, then the last '
starts the second string.
Escaping double quotes is a lot easier and simply requires \"
.