Assignment 6, due Mar 24
Part of
the homework for 22C:50, Spring 2003
|
Always, on every assignment, please write your name legibly as it appears on your University ID and on the class list!
Consider the following UNIX shell script (using the tcsh shell)
#tcsh
# count n
# where n is a number,
# count up to but not including n;
# outputs the successive numbers 10 numbers per line
#
set limit = $1
set count = 0
set components = 10
set component = 1
set linebuf =
while ( $count < $limit )
set linebuf = "${linebuf} ${count}"
@ count ++
@ component = $component + 1
if ( $component > $components ) then
echo $linebuf
set linebuf =
set component = 1
endif
end
if ( $component > 1 ) echo $linebuf
Install this in a file called count on a Unix or Linux system.
Use the chmod +x count command to make this file
into an executable shell script. Try the count 26 command
to verify that it works. Then do the following:
Modify count so that count n outputs the first n members of the series 0 1 1 2 3 5 8 etc. (This is the well-known Fibonacci series; each member is the sum of the two previous members). (1.0)
Note: turn in a listing of your solution; it might be 5 lines longer than the above; use the man tcsh command if you need to see the manual for the tcsh shell language.
Do problem 5 (1.0) at the end of chapter 8 of the notes.
Do problem 2 (1.0) and 6 (1.0) at the end of chapter 9 of the notes.
Write a shell script that takes, as an argument, a list of numbers, and outputs that list in sorted form. Save your script in a file called mysort in your mp4 directory; turn in a listing of your script. your script should be clearly commented! Here is an example of how it might act in one run:
% mysort 1 26 3 234 15 80 12 1 3 12 15 26 80 234
For extra or honors credit, measure its performance and turn in a brief report on your results extimating the big O performance of your script. Note that Unix systems have a time command.
Here is another shell script example that may prove useful
#tcsh
# args a b c ...
# where a, b, c etc are any arguments;
# outputs the number of arguments and then each argument
#
echo \$\#argv = $#argv
set count = 1
while ($count <= $#argv)
echo \$argv\[$count\] = $argv[${count}]
@ count ++
end