Shell Processing Order
- Split command line into tokens ( SPACE, TAB, ; ...)
- Check for key words ( if, while, for ...)
- Check for aliases ( alias dir='ls -l' )
- Tilde (~) expansion
- Variable substitution ( $varname )
- Command substitution ( $(command_name) )
- Arithmetic Evaluation ( $(( x = 2+3 )) )
- Split into tokens using the IFS normally this is white space
- Wilcard expansion ( * ? [] )
- Command lookup
- builtin commands
- functions defined by user
- executable programs on the system in its PATH
- Redirection ( < > .. )
- Run the actual command
Special Characters and Quoting
You can precede the a special character with a backslash (\) to escape its special meaning. There are three kinds of quotes available and all three are DIFFERENT.
- Strong Quote ' (the one beside the ENTER key)
- Weak Quote " (double quote)
- Command substitution ` (this is for backwards compatibility and should be avoided)
- Backslash (\) protect the next character
Strong Quote
String quote will NOT perform any special interpration of the characters. You cannot have single quotes inside single quotes even if you precede them with a backslash
Weak Quote
Weak quote performs selected substitution. A strong quote inside a weak quote has no effect. You can include a double quote inside a double quote only if you PRECEDE it with a backslash (\). You also need to escape the dollar sign ($) inside double quotes, the (`) command subsitution and the (\) backslash itself.
Weak quote will evaluate steps 5-7 in the shell processing order:
- Variable substitution ( $varname )
- Command substitution ( $(command_name) )
- Arithmetic Evaluation ( $(( x = 2+3 )) )
Examples of quoting
$ cd
$ mkdir dir_qoutes
$ cd dir_quotes
$ touch file_one
$ name=derek
$ echo *
$ echo $name
$ echo $(ls)
$ echo * $name $(ls)
$ echo '* $name $(ls)'
$ echo "* $name $(ls)"
$ echo \* \$name \$\(ls\)