Description
1. UNIX/LINUX commands typically expect lines to be terminated by newline characters rather than
carriage return characters. Lines terminated with carriage return characters can cause unusual and
unexpected results.
(a) Download the file L6Q4.with_cr.txt.tar from the lab index page. Use the tar(1) command to
un-archive the file (to L6Q4.with_cr.txt).
(b) Use the pr(1) command in the same way as you did in question 3 of Lab 6 to output L6Q4.with_cr.txt
(from part (a)) with line numbers.
(c) Use a UNIX pipeline involving hexdump -c and grep to show that L6Q4.with_cr.txt contains
carriage return characters rather than, or in addition to, newline characters. The logic of the
pipeline is that if grep(1) outputs anything (any lines), then L6Q4.with_cr.txt contains carriage
returns. Note that hexdump -c represents a carriage return character by “\r” and newline by
“\n” Make sure to have grep look for “\r” and not “r”.
2. (a) Create a C (not C++) program called test_math.c that:
• includes the system-wide math.h header file for the math library;
• reads a floating-point number (type float) from the standard input;
• calls the sinf() function (in the math library) with the input value as argument;
1
• prints, to the standard output, the result from calling the sinf() function.
Keep your test_math.c program as simple as possible. Submit your test_math.c program as
part of your lab solution.
(b) Compile (with gcc), link, and run your finished program, testing it with a few input cases. Extensive testing is not necessary. Make sure that your program compiles, links, and runs without error.
However, compiler warnings about the parameters to main() not being used can be tolerated.
(c) Compile (with gcc) your test_math.c file from part (a) to an object module rather than producing
an executable file. You should end up with an object module named test_math.o. Confirm that
it is an object module using the file(1) command.
3. The behaviour of some commands can be modified by setting or changing environment variables. Determine which environment variable you would modify to make grep case-insensitive. (Don’t submit a log
of this.) Then change this environment variable appropriately using the syntax “export VARIABLE=value”
(in bash). Finally, execute the command “grep a <<< A” to show that grep now ignores case. Note:
do not change locale settings.
4. The command “ls -l ~” will show the permissions and ownership, among other information, for each
file in your home directory. However, suppose that you wish to show these attributes for your home
directory itself (rather than the contents of your home directory). Use a UNIX command to do this.
Like the ls command above, your command must use “~” as the argument.
2

