I'm trying to create a shell script where the command lists all the readable and executable permitted files for me or the current user, whomever it may be and wherever the location of the user. So even if I change permissions in the future, the changes will still be reflected.
This is what I have so far:
user=`id -un`
group=`id -gn`
IFS='
'
for file in `ls -al /home/cg/root`; do
perm=$(echo $file | awk '{print $1}')
fileowner=$(echo $file | awk '{print $3}')
filegroup=$(echo $file | awk '{print $4}')
ownerreadbit=${perm:1:2}
ownerexecbit=${perm:3:4}
groupreadbit=${perm:4:5}
groupexecbit=${perm:6:7}
worldreadbit=${perm:7:8}
worldexecbit=${perm:9:10}
if ["$user"=="$fileowner" && "$ownerreadbit"=="r" && "$ownerexecbit"=="x"]; then
echo $file
elif ["$group"=="$filegroup" && "$groupreadbit"=="r" &&" $groupexecbit"=="x"]; then
echo $file
elif ["$worldreadbit"=="r" && "$worldexecbit"=="x"]; then
echo $file
fi
done
-writable
for writable files ;-). – Stephen Kitt Mar 02 '18 at 13:44