Ubuntu Unleashed 2019 Edition: Covering 18.04, 18.10, 19.04

(singke) #1

confirms its value as 0 for true before allowing the next command to be run.
Again, the letters represent commands:


Click here to view code image
matthew@seymour:~$ i && k


You can do exactly the opposite with ||, which runs the following command
only if the first one returns an exit status of 1 for false:


Click here to view code image
matthew@seymour:~$ m || n


Running Separate Commands in Sequence


If you want to have a set of commands run in order but not use the output
from one as the input to the next one, you can. Separating commands with a ;
(semicolon) causes the system to treat each item as if it were entered on a new
line after the previous item finished running. Let’s say you have three
commands, doctor, rose, and tardis. You could run each in order by
using this command:


Click here to view code image
matthew@seymour:~$ doctor ; rose ; tardis


Note that the spaces before and after the semicolons are optional, but they do
make the line easier to read.


Process Substitution


Sometimes the output of one or more commands is precisely what you want
to use as the input to another command. You can use output redirection for
this purpose, using what we call process substitution. In process substitution,
you surround one or more commands with ( ) and precede each list with a
<. When you do this, do not insert a space between the < and the opening (.
The resulting command looks like this:


Click here to view code image
matthew@seymour:~$ cat <(ls -al)


This first example is really the same as ls -al | cat. With only the
output of one process being involved, it doesn’t seem worth learning an
additional command.


In the following example, you take the output of two ls commands as input

Free download pdf