NAME: .......................................... DUE DATE: Jan 19, 1999
1. (10 points)
List the name of each file in the current directory(or any subdirectory of it) which is a regular file, together with the first line of the file.
A regular file is essentially one which is not a directory.find . -f | tee f1 | head -1 f1
2. (10 points)
Write a script which will take text input from standard input, and copy it to standard output with each line preceded by a line number in the same manner as cat -n. Do not use the command cat.
LN = 1
while read LINE
do
printf "%6d %s+\n" $LN $LINE
LN=$( echo "$LN + 1" | bc )
done3. (10 points)
Write a script called saytime which will print out the current time in words.
Parse date and Use case stmt. Full credit will be given if you can show that you wanted to solve it in similar lines4. (20 points)
Write a function changedir which will prompt you for a directory name and cd to that directory. Why must you use a function, and not a script?changedir() {
echo "Enter the dir name:"
read DIRNAME
cd $DIRNAME
}
5. (20 points)
Write a script which will every minute display the date and time, but when run in the foreground will terminate if it receives ctrl-C 3 times.
6. (30 points)
Write a script called pythagoras which will take two numerical arguments, representing the base length and the height of a right-angled triangle, plus one or two options -a and -h(meaning area and help). With option -a, the area of the triangle will be printed on standard output preceded by the message AREA is, and with option -h a short help message will be printed. With no options, there will be no output; any other option will be ignored, except that a warning message will be output on standard error.