The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 03-18-2009
morava morava is offline
Registered User
  
 

Join Date: Mar 2009
Posts: 5
One more expression syntax error

HI again, still working on the assignment, which is really hard given we just started unix 4 weeks ago. This script should change the permission for the user depending if its x, w or r, to the opposite. When i try to run it, I am getting expression error. Can you spot where the problem is? I really really appreciate it !!
Thanks so much !!


#!/bin/csh
# This script will accept a file name as one argument and the word
# read, write or execute as the second argument
# On top of that, it will switch the permissions to the opposite one
if ($2==read)
if (-r $1) then
chmod +r $1
echo Permission changed to readable
else
chmod -r $1
echo Permission changed to not readable
endif
else if ($2==write)
if (-w $1) then
chmod +w $1
echo Permission changed to writeable
else
chmod -w $1
echo Permission changed to not writeable
endif
else
if (-x $1) then
chmod +x $1
echo Permission changed to executable
else
chmod -x $1
echo Permission changed to non executable
endif