about -w

-w "filename"

is suppose to return 0 if the file got write permission and 1 if not right?

for some reason... when i test it, it keep returning 1 even after i set full 777 permission to that file/directory?

the directory will become /path/path2/path3

directory = `dirname /path1/path2/path3/file.txt`

if [ -w "$directory" ]
then
   echo $?
else
   echo $?
fi
directory=`dirname /path1/path2/path3/file.txt`

Change this line .. no spaces... Scripting does not like spaces
Likes to be close .. while with variable. :slight_smile:

1 Like

ah right, that's true haha..

tried that doesnt work too, still showing i dont have permission... even tho its showing that everyone got full drwxrwxrwx permission...

Please post the output from:

ls -ald /path1/path2/path3
ls -lad /path1/path2/path3/file.txt
id

Does you system have acl's ie.,
in ls -l output do you see

drwxrwxrwx+

some character after the perms?

What OS and shell are you using?

1 Like

ok now that's funny.... it shows no such file or directory..., dont think i got typo..

using bourne shell, unix

yeh it's showing drwxrwxrwx

Please can you type the commands which you are asked to type and post the full output, not just the bit which you think is relevant. Also, if you get an error message please post what you typed and the complete and exact matching error message.

ah... i found the problem.. im in directory path2 and i go and type all the path...

directory = `dirname /path1/path2/path3/file.txt`

if [ -w "$directory" ]
then
   echo $?
else
   echo $?
fi

Try to remember to not put space characters around the equals sign in a Bourne Shell variable assignment.

Not the first time ...
http://www.unix.com/shell-programming-scripting/181353-question-about-syntax-error.html

1 Like

haha yeh ill try to remember that, used to java coding..

Thanks for the warning methyl, jim mcnamara and chakrapani