4.3.10 Typical command sequences
Let's try to remember following shell command idioms. See Shell parameters, Section 13.2.3,
Shell redirection, Section
13.2.4,
Shell conditionals,
Section 13.2.5, and
Command-line
processing, Section 13.2.6 after reading these idioms.
4.3.10.1 command &
The command is executed in the subshell in the
background. Background jobs allow users to run multiple
programs in a single shell.
The management of the background process involves the shell built-ins:
jobs, fg, bg, and kill.
Please read the sections of the bash(1) manual page under
"SIGNALS", "JOB CONTROL", and "SHELL BUILTIN
COMMANDS". [
29]
4.3.10.2 command1 | command2
The standard output of command1 is fed to the standard input of
command2 . Both commands may be running
concurrently. This is called pipeline.
4.3.10.3 command1 ; command2
The command1 and command2 are executed
sequentially.
4.3.10.4 command1 && command2
The command1 is executed. If successful, command2 is
also executed sequentially. Return success if both
command1 and command2 are
successful.
4.3.10.5 command1 || command2
The command1 is executed. If not successful,
command2 is also executed sequentially. Return
success if command1 or command2 are
successful.
4.3.10.6 command > foo
Redirect standard output of command to a file
foo. (overwrite)
4.3.10.7 command >> foo
Redirect standard output of command to a file
foo. (append)
4.3.10.8 command > foo 2>&1
Redirect both standard output and standard error of command to a
file foo.
4.3.10.9 command < foo
Redirect standard input of command to a file
foo. Try:
$ </etc/motd pager
... (the greetings)
$ pager </etc/motd
... (the greetings)
$ pager /etc/motd
... (the greetings)
$ cat /etc/motd | pager
... (the greetings)
Although all 4 syntaxes display the same thing, the last example runs extra
cat command and wastes resources with no reason.