Below are selected solutions for the Chapter 20 workshop questions from Cybersecurity Ops with bash. Note - These are just examples, many possible solutions exist.
Try expanding and customizing the features of softinv.sh by adding the following
Modify the script to add, for Linux distros only, an ls of the /bin and /usr/bin
The ls command that we want to run on the Linux systems is something like this:
ls -b /bin /usr/bin
You might want to add other options to the ls command. We used the -b option to show any non-printing characters in the filenames. You might also consider adding /sbin and /usr/sbin as other directories to be listed; these are the directories used by the root (privileged) user.
1. We set a variable (LNONLY) to hold the string that is that command:
Later on, for the case statement for windows systems we unset the variable so that the variable is no longer defined.
2. At the bottom of the script, we can execute the command:
The shell will replace the values of LNONLY and OUTFN and then execute the resulting command line. On a Linux system the ls command will be run. The redirects on this command throw out any errors and append all the regular output to the $OUTFN file (defined earlier in the script). In the case of an Windows OS we have unset the variable LNONLY, so the variable reference is replaced by nothing, by emptiness (not a null string, but by no thing). All that is left to execute are some harmless redirects.