2.9. Strings

A string constant in a shell script is anything enclosed in single quotes ('this is a string') or double quotes ("this is also a string").

Unlike most programming languages, text in a shell scripts that is not enclosed in quotes and does not begin with a '$' or other special character is also interpreted as a string constant. Hence, all of the following are the same:

shell-prompt: ls /etc
shell-prompt: ls "/etc"
shell-prompt: ls '/etc'

However, something contains white space (spaces or tabs), then it will be seen as multiple separate strings. The last example below will not work properly, since 'Program' and 'Files' are seen as separate arguments:

shell-prompt: cd 'Program Files'
shell-prompt: cd "Program Files"
shell-prompt: cd Program Files


Special sequences such as '\n' must be enclosed in quotes or escaped, otherwise the '\' is seen as escaping the 'n'.

Hello\n != "Hello\n"
"Hello\n" = 'Hello\n' = Hello\\n