4.1 Assigning data to variables

Any string can be stored in a variable by using the operator = without spaces before and after, if spaces are added between the operator “=” an error will be prompt.

$ a = 10
$ #a: command not found
$ a=10
bash: line 1: a: command not found

You must use quotes (“) to include spaces.

$ b=Hello world
$ b="Hello world"
bash: line 1: world: command not found

Use backslashes (\) to escape special characters that shoudl not be interpreted, such as a double quote in the next example:

$ c="Be careful with "!"
$ c="Be careful with \"!"
bash: -c: line 2: unexpected EOF while looking for matching `"'

Note that on a Mac, the above lines will not work due to the exclamation mark. If you want to run it, use single quotes instead of double quotes. In the above case, this also eliminates the issue of escaping:

$ c='Be careful with "!'

Unless you want to warn of single quotes, of course:

$ c='Be careful with \'!'
bash: -c: line 1: unexpected EOF while looking for matching `''

Single quotes and double quotes have different meaning, however. We will delve into that below