#! /bin/sh -
n=0
for file do
if [ -r "$file" ]; then
printf '"%s" is readable\n' "$file"
n=$((n + 1))
else
printf '"%s" is not readable\n' "$file"
fi
done
echo "$n out of $# files were readable"
[ -r file ]
test whether the file
is readable by the process invoking that [
command, so by you, the user running that script, typically using the access()
system call.
It doesn't say anything about whether other users may be able to read it. It doesn't attempt to read it either. For instance, it won't be able to detect files that are un-readable because the underlying storage is defective.
shebang
doesn't seem right – NarūnasK Mar 15 '17 at 17:26#! /bin/sh
would be incorrect. – Stéphane Chazelas Mar 15 '17 at 19:16#!
and/bin/sh -
which after further reading appeared to be optional and having space inshebang
definitely is not an error, hence apologies for confusion. – NarūnasK Mar 16 '17 at 09:49