Here are some exercises to try out what you have learned today and combine commands to do something interesting without doing a lot of typing. Although you are not “emperor penguins” just yet, you have been exposed to a significant amount of material. Some of these are a boit challenging and will require you to learn a bit more linux.
E1 This was mentioned before. See if you can determine the rule for classifying a year as a leap year. It is somewhat more complicated than just being divisible by 4. As mentiuoned above, the year 1700 is anomalous. (Try not to just google the answer.)
E3 Rewrite the bc file f2c.bc so that it performs the reverse calculation, that is, takes a temperature in Celsius and converts it to the Fahrenheit scale. Call if c2f.bc.
E4. Measure the time necessary to compute the geometric quantity pi to a given number of decimal places, say 1000. Then repeat the calculation for 1500, 2000, 2500 and 3000 places. Is the computation time linear with the number of decimal places? You will need the builtin bc utility and remember that tangent(pi/4) = 1. The linux builtin time and echo commands will be useful. You can make the time measurement in a single line but may struggle with the quotation marks.
E5. See if you can write a single-line command or short script that determines the total number of processors on the machine you are currently logged onto. The file /proc/cpuinfo is helpful.
E6 There is a joke attributed to Professor Hagstrom in my home directory. Can you improve on it?
E7. Write a script that periodically checks that a given process, identified by its PID number, is still running. Name the script check and it single argument should be the PID of the process. It should somehow notify you that the process has ended. The command mailx can be useful for this. You will also need a process that runs for some tens of seconds so check has time to check on it.
E8. Somebody has given you a text file for proofreading and comments. The file is single-spaced, making reading and commenting difficult. Write a script that adds a blank line between every line in the original file and writes the modified file to a file of your choosing. You want to use the awk (often labeled gawk) utility. We did not cover this in the notes but see if you can learn enough of it to handle the exercise. You can do it in one line.