Command+Line+Processing+Cheatsheet
Command+Line+Processing+Cheatsheet
HOW BASH
PROCESSES
COMMAND LINES
STEP 1: TOKENISATION
During tokenisation, bash reads the command line for
unquoted metacharacters, and uses them to divide the
command line into words and operators.
LIST OF
METACHARACTERS
Space
Tab
Newline
|
&
;
(
)
<
>
Bash will then break the command line down into simple and
compound commands.
Command
Command
Line
Line
Simple Compound
Commands Commands
SIMPLE COMMANDS
LIST OF LIST OF
CONTROL REDIRECTION
OPERATORS OPERATORS
Newline <
I >
II <<
& >>
&& <&
; >&
;; >|
;& <<-
;;& <>
|&
(
)
EXAMPLE:
echo a
_b_c
_ echo _1 2
_ _3 - Interpreted as one simple command
because there are no control operators.
echo a b c ; echo 1 2 3
echo a_ b_ c
_ ; echo _1 2_ 3_
echo a
_b_c
_ ; echo _1 2
_ 3_
echo
This is a b c ; echo 1as2 two
interpreted 3 simple commands because there is
a control operator that ends the first command.
Example:
STAGE
Brace Expansion
Parameter expansion
Arithmetic expansion
STAGE
Command substitution
Tilde expansion
STAGE 2
Parameter expansion
Arithmetic expansion
Command substitution
Tilde expansion
Example 1 Example 2
(Word Splitting) (No Word Splitting)
numbers=”1 2 3 4 5” numbers=”1 2 3 4 5”
touch $numbers touch “$numbers”
touch 1_ 2
_ _3 4
_ 5
_ touch “1 2 3 4 5”
Note 4: You can modify the IFS variable just like any other
variable.
[
Matches any one of the enclosed
characters, but requires a character to
be there.
[:alpha:] [[:alpha:]]
@
Happy if the pattern list matches once
ls !(london|paris)*.@(jpeg|png|jpg)
In this case, this pattern will
match all the image files with
the word newyork at the
beginning.
echo ‘ “hello” ’
The double quotes are retained, however,
because they are quoted by the single
quotes that surround them.
echo \”hello\”
The double quotes are retained, however,
because they are quoted by their
preceding backslashes.
Note 1: Not all commands use every data stream. The best way
to find out what streams a command uses is to try it out, or to
read its manual page