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

Check for your errors yourself ... :smiley:

#!/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 ) then

        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 ) then

                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
        endif
endif

Hi again, still not working. I got the spaces figured out with my teacher, but i cannot fix the logic. What I have right now is three sections: read, write, execute. If I say: "If the file is not readable, change it to readable and echo the appropriate message, otherwise change it unreadable" If I leave it with +r | -r | +r, it works, except it only echoes The file has been changed to readable (writeable, executable) If I change the permissions to -r | -r | +r or anything similar, it returns the expression syntax. In the read section I show the adjusted one (with expr. syntax), in other two sections what I had originally, it works except returns the first echo only

#!/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) then
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) then
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
endif

Thread closed. Please read the Forum Rules and do not post homework assignments.