#!/bin/tcsh 

# invokes command supplied by the first argument on every file and directory (recursively)
# command takes a file as argument
# this script and the command must be known to the system, it must be placed in a directory of the PATH,
# otherwise they cannot be called recursively on all subdirectories  

#echo 'start script forallfiles'

if ($#argv == 0 ) then
    echo "No arguments supplied: we use the wordcount wc"
    set COMMAND=wc
else 
    set COMMAND=$argv[1]
endif

foreach file ( `dir` )
 
  if (-d $file) then
    cd $file

    echo "Executing <$COMMAND> on directory <$file>:"
    forallfiles.csh $COMMAND 
    cd ..
  else 
    if (-e $file) then
#	echo "executing $COMMAND on file $file..."
	$COMMAND $file
    endif
  endif
end

#echo 'end script forallfiles' 
