Page 49 - Raspberry Pi as a Foundation for Boosting Computer and Technology Literacy
P. 49

Customizing the system and the shell  3.4
              Additionally, a personal recommendation from one of the authors
            would be to also add the following aliases for the cp, mv, and rm com-
            mands:

              alias cp=’cp -v -i’
              alias mv=’mv -v -i’
              alias rm=’rm -v -i’
              These aliases will make these commands more verbose (-v) and in-
            teractive (-i), which can help prevent accidental overwrites and dele-
            tions by asking for confirmation before executing.

            Fetching a random man page
            Last, but not least, let us create a bash script, which is essentially a file
            that can contain multiple commands along with additional program-
            ming syntax, such as variables. This allows a user to create their own
            command line tools that can accept flags and arguments. For demon-
            stration purposes, we will create a small and simple script for fetching
            and displaying random man pages, so the reader can learn more about
            various shell commands on their own.
              We shall begin by creating an empty file inside the home folder
            (name it “randman”, for instance) using the  touch command and
            then opening it with Nano:

              touch randman
              nano randman
              The first line of any shell script must be a shebang, which informs the
            system about which interpreter to use for the script. In our case, we
            are using bash, so we must include the following:
              #!/bin/bash
              Next, let us design a command that will fetch a random man page:










                                                 Figure 3.25
                                                 The output of the find
                                                 command is redirected into awk
                                                 and then into sed


                                                            49
   44   45   46   47   48   49   50   51   52   53   54