Due Thursday, November 29
For this assignment you should write a C shell script that prints the largest file in either the current working directory or a directory specified on the command line. Here is an example of what you should see when you run your program.
ub 41% biggest /home/volc/47/gshute/www/cs3011/pa8/pa.html has size 775 ub 42% biggest nothing nothing has no non-empty files
The program should start with a check to see if there is a command-line argument and set a "directory" variable to the argument if it exists, or the current working directory ($cwd). Then set a "size" variable to 0. Then for each file (only count regular files) in the directory, get its size and compare it to the "size" variable. If the new file size is greater than "size" then set "size" to the new file size and set a "biggestFile" variable to the name of the file.
After checking the files, your "biggestFile" variable should be defined only if the directory contains a non-empty file. You can use this fact to determine what message to print using the "echo" command.
Most of what you need to know to write the shell script is described in The C Shell tutorial. One thing that is not described there concerns finding the size of a file. You can display the size of a file by executing the command "wc -c fileName". The output shows both the size and the name of the file.
Inside a shell script you can use the wc program to set a variable with the following statements.
set wcOut `wc -c $file` set newSize = $wcOut
The first statement executes the wc command and assigns its output to the script variable "newSize". Since the wc program has two words of output (the size and the file name), you need to access the output as an array to get just the size.