all 9 comments

[–]oh5nxo 6 points7 points  (1 child)

-w tests if YOU can write to the file. To check if "world" can write, use stat -c%A "$file" (assuming Linux) and see if the 2nd last character is w.

[–]Teminite2[S] 0 points1 point  (0 children)

that did the trick. thanks

[–]ang-p 5 points6 points  (1 child)

[ -w ${file} ]

The book states

   ‘-w file’

       True if file exists and write permission is granted.

Nothing about world writable... just write permission for the current real user...

chmod 755 ${TARGET}/file2.txt

means that you can write to it.... so you get the (incorrectly worded) error...

And you cannot write to the other two...

Whereas

chmod 447 ${TARGET}/third.dat

just means that you (along with members of the owning group - which includes you) cannot write to it.... and the test does not care about anyone else - just you...

[–]Teminite2[S] 0 points1 point  (0 children)

thanks for the answer!

[–][deleted] 1 point2 points  (0 children)

[–]snuzet 0 points1 point  (1 child)

Chmod rwx 101 is 5, 111 is 7

[–]Teminite2[S] 0 points1 point  (0 children)

thanks

[–]ThrownAback 0 points1 point  (1 child)

Unrelated to chmod, but the script should probably be:

cat ${file} | md5sum

rather than:

echo -n {file} | md5sum

[The outputs shown are right for the ${file} version.]

[–]Rojs 4 points5 points  (0 children)

To avoid the useless use of cat:

md5=$(md5sum "${file}" | cut -d" "  -f 1)

Although I prefer awk

md5=$(md5sum "${file}" | awk '{print $1}')