#! /bin/csh
# pchmod; is a script to change mode for a path.

# check that there is no "/" in args
echo "$*" | grep "/"
if ($status == 0) then
echo args should not contain "/"
exit 1
endif

# be sure that the file exists
echo "The file you want to change its mode is:"
ls -l $argv[$#argv]
if ($status != 0) then
echo file $argv[$#argv] does not exist.
exit 1
endif

# put the current path in e and assign it to the variable d
set e=`pwd`
set d=$e

# loop on d from the current directory till the HOME directory.
# d is being changed by cd to the parent and `pwd`.
# within the loop the mode of each directory is being changed.
while ($d != $HOME)
echo $d
chmod o+x $d
cd ..
set d=`pwd`
end

# return back to the current directory and chmod for the file.
cd $e
chmod $*


Back to Assignments Page
Back to CS476/576 Home Page