Exercises
See Appendix A for answers to the following exercises:
[6] Write a program that changes to some particular (hardcoded) directory, like the system’s root directory, and executes the
ls -lcommand to get a long-format directory listing in that directory. (If you use a non-Unix system, use your own system’s command to get a detailed directory listing.)[10] Modify the previous program to send the output of the command to a file called
ls.outin the current directory. The error output should go to a file calledls.err. (You don’t need to do anything special about the fact that either of these files may end up being empty.)[8] Write a program to parse the output of the
datecommand to determine the current day of the week. If the day of the week is a weekday, printget to work; otherwise, printgo play. The output of thedatecommand begins withMonon a Monday.[336] If you don’t have adatecommand on your non-Unix system, make a fake program that prints a string similar to one thatdatemight print. We’ll give you this two-line program if you promise not to ask us how it works:#!/usr/bin/perl print localtime() . "\n";
[336] At least when the days of the week are being given in English. You might have to adjust accordingly if that’s not the case on your system.
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access