Quote:
Originally Posted by
spider-man
Ok, I get you.
If I test -d and test -f, and fail, how can I tell if the path takes me to a file or a directory?
Because for the error message, I need to say something like:
PHP Code:
echo "File 'abc.txt' does not exist."
The whole point is that
test -d fails fails then
file is not a pathname naming an existing directory. Once you know it is not a directory if
test -f fails fails then
file is not a pathname naming an existing regular file. It isn't clear to me whether you want to use
test -e file (a file of any type exists with that name) or
test -f file (a regular file exists with that name). The directions in your assignment are to change the mode one way if the current argument names a directory, change the mode another way if it is an existing file that is not a directory, and report an error if the file doesn't exist.
Note that according to the standards a directory is a file. Your comments make it sound like a directory is not a file (and the assigment text has the same ambiguity). There are several types of files including: directories, regular files, block special files, character special files, pipes, symbolic links, sockets, etc. Some people say "file" when they mean "regular file". Some people (and the standards) say "file" when they mean a file of any type. If your professor hasn't discussed this, you may want to ask for clarification of your assigment to determine if you're supposed to use
chmod a+r for all files that are not directories or to only use
chmod a+r for regular files.
Should you be checking whether or not the invocations of
chmod succeed?