only contains a single value, the loop will only cycle once. At least probably once. Since you didn't quote it, the shell would break up any multi-word entries and attempt to cycle over the parts.
What you really want is probably this:
Also, The -r
test isn't for "read-only", it's for "readable", which is a different thing. What you should probably do is use stat
to get the full set of file permissions and then test against that. Parsing ls
for file info is not recommended.
How can I get a file's permissions (or other metadata) without parsing ls -l output?
You should also add a test to ensure that $a
is a valid directory before running the loop on it. I also suggest using more meaningful variable names. Single letters tend to make code less understandable and so should be avoided in all but the simplest cases.