#!/bin/csh # example from pp. 526-527 of Sarwar, Koretsky, Sarwar (2001) # called fs there - purpose is to display total size of files in directory # demonstrates a string array called files, numeric variables and arithmetic if ( $#argv == 0 ) then set directory = "." else if ( $#argv > 1 ) then echo "Usage: $0 [directory name]" exit 0 else if ( ! -d $argv[1] ) then echo "Usage: $0 [directory name]" exit 0 else set directory = $argv[1] endif # initialize files array to file names in the specified directory set files = `ls $directory` # initialize some numeric variables @ nfiles = $#files @ index = 1 @ sum = 0 # custom changes required for mikec's csil account: unalias 'ls -l' # force use of original ls -l command @ sizefield = 5 # for systems that have a group field - else 4 # loop once for each file in list while ( $index <= $nfiles ) set thisfile = "$directory"/"$files[$index]" if ( -f $thisfile ) then # an ordinary file, not directory or other set argv = `ls -l $thisfile` # set command line arguments @ sum = $sum + $argv[$sizefield] endif @ index++ end # spell out the current directory if ( "$directory" == "." ) then set directory = "your current directory" endif echo "The size of all non-directory files in $directory is $sum bytes." exit 0