#!/bin/csh
# Paul K Flynn CS576/763 Assignment 1 Fall 97
# pchmod options file
# test for exceptions first
set i = $#argv
if ($i <2 )then
echo pchmod : ERROR : invalid number of arguments
exit 1
endif
#check for the / in the file
echo $argv[$i] | grep / >> /tmp/f$$
if ($status == 0 ) then
echo pchmod : ERROR : do not use '"/"' in args
rm /tmp/f$$
exit 1
else
# file name form was okay
#see if the file exists
if ((-f $argv[$i])||(-d $argv[$i])) then
# file does exist
# remember where it is
set here = `pwd`
#chmod of dirs leading to here
echo / >> /tmp/f2$$
while (1)
set new = `pwd`
# chmod of this one then step up
chmod o+x $new
cd ..
echo `pwd` >> /tmp/f3$$
cmp -s /tmp/f2$$ /tmp/f3$$
if ($status == 0)break
# we arrived at root
rm /tmp/f3$$
# else we made a successful cd
end
#clean up
rm /tmp/f2$$
else
echo pchmod : ERROR: $argv[$i] does not exist
exit 1
endif
cd $here
chmod $argv
rm /tmp/f$$
endif