BASH:find out if volume "foo"/folder "goo" can be written to
My habit is to write BASH scripts that export output to ASCII text files, typically in the same directory as the files they're evaluating. It occurred to me recently that, with read-only volumes, or in directories where my permissions may be "less than 776," that could throw an unfriendly error or two in my direction. To avoid it/work around it, I'd like to know the best way(s) of determining the write-ability of a folder before I run a script on it OR have the script 'ping' for write status/privileges in the directory it's in and dump its output there or elsewhere, as appropriate.
What command would one use, and how would one parse the output?
I have a suspicion that stat might be useful, and I know from perusing the man page that there are %-letter tags that will "pull out" attribute data for a file or folder. Just now I did a 'stat' command, and I noticed in two fields there were zeros. Is this a practical "rule of thumb" when determining whether or not a volume is write-able?
Regarding the permissions of folders:
I'm familiar with the different options to 'ls', but here again I think 'stat' may be the better approach, owing to the attribute "print out" options I mentioned above. Here I suppose it's a question of "which one gives up the goods with less hassle," or "which one can be counted on to 'tell the truth' about folder WXYZ right off the bat." stat I can parse; I have zero practise at pulling ls's teeth, so to speak.
Any advice on this matter would be much appreciated.