Page 37 - Raspberry Pi as a Foundation for Boosting Computer and Technology Literacy
P. 37
Overview of shell commands 3.3
Figure 3.10 Example of using the AND chain operator
Figure 3.11 Example of using the OR chain operator
The AND operator means that the next command will run only if
the previous command succeeds. Therefore, the string “Connected
to the internet!” (\n initiates a new line) will only be displayed
if the system was able to reach “google.com”, indicating that we indeed
have an Internet connection (Figure 3.10). Otherwise, only the ping
command will be executed, and its stderr will be displayed.
Last, but not least, consider the following example of the OR oper-
ator usage:
ls projects || mkdir projects
The command to the right of the OR operator will only execute if the
command to the left fails. As a result, the mkdir command will cre-
ate a “projects” directory only if the ls command attempts to access a
non-existent directory (Figure 3.11).
Obviously, all chaining operators could be used together to combine
various commands and create different clever algorithms.
3.3 Overview of shell commands 3.3
Next, let us go over some of the essential operations that a user might
want to perform and how they can be accomplished within a terminal.
This includes updating the system, installing and removing software,
creating and manipulating files, monitoring system resources, and in-
teracting with networks. Hence, the subsequent subsections aim to
demonstrate the speed and efficiency of performing these operations
using the shell commands, in contrast to using some GUI software.
37