Module 02.3 - Quoting and Control Statements
Module 02.3 - Quoting and Control Statements
Quoting
Double Quotes
● Double quotes tell the shell to not interpret the special characters (meta characters).
Meta characters are symbols that have special meaning to the shell ( *, ?, space, and etc ).
● Double quotations are used display or use a value that is a special character to the shell.
● Double quotes allow the user of command substitution, variable substitution.
ivanovn@atlas:~$ var=hello there
● In the above example, the space divided the “var=hello threre” statement into two parts:
● var=hello
● there (this is not a valid statement and, as a result, a syntax error was shown
● The double quotations can be used to fix the above statement:
var=“hello there”
Single Quotes
● Single quotes prevent the shell from doing any interpreting of special characters,
including globs, variables, command substitution and other metacharacters.
ivanovn@atlas:~$ var=hello
$var
Backslash Character
● A backslash character is an escape character – it takes the special meaning away from meta
characters and other special characters.
ivanovn@atlas:~$ var=hello
ivanovn@atlas:~$ echo $var
hello
ivanovn@atlas:~$ echo \$var
$var
ivanovn@atlas:~$ echo *
Desktop Documents Downloads Music Pictures Public Templates Videos
ivanovn@atlas:~$ echo \*
*
Today is date
● To execute the date command so the output of the date command is sent to
the echo command, put the date command inside of two backquotes:
ivanovn@atlas:~$ echo Today is `date`
● Alternatively, the command substition can be done by placing the command inside of
$()
ivanovn@atlas:~$ echo Today is $(date)
● The above examples will print “success” if the ls command succeeds and will print “failure” if the ls
command fails