file permissions using shell scripting

Hi
I am trying to use shell script to display file permissions, and I can do it fine for the current user logged in, but now I want to view all file permissions for the Owner of the file, Group users and everyone, so it will look something like this:
-----------------READ WRITE EXECUTE
OWNER Username ---YES---YES---NO
GROUP USERS ---YES---NO---NO
EVERYBODY ---NO----NO---NO

Below is what I have so far.

echo -n "please enter file name : "
read file 
[ -w $file ] && W="Write = yes" || W="Write = No"
[ -x $file ] && X="Execute = yes" || X="Execute = No" 
[ -r $file ] && R="Read = yes" || R="Read = No" 
echo "$file permissions $W $R $X" 

so my question is how do I find out the other permissions of the file?.

Any hints of tips would be greatly appreciated.

thanks

I confess I think you are making life overly difficult for yourself.

To display the owner, group and permissions on a bunch of files you can use find to get the files and then exec to display the info.....

find <dir> -exec ls -l {}\;

If you want to chop out different columns from the ls -l output then awk will be a good avenue of exploration.

I think that rwxr-wr-- is just as understandable as
yesyesyyes yesnoyes yesnono

If you do not want to include dirs in the find then...

find <dir> ! -type d -exec ls -l {}\;

I could do this easy with awk, but my unreasonable employer wont let me use with awk or sed :(.

He wants a simple script to view it with yes no so other non IT related departments can understand it.

but thx for the reply, ill try out your sugession.

how would i search the strings like rwxr-wr--, or put it in a variable. if i can achieve this i can just search the string for certain characters and print out statment based on those characters.

Your teacher is now your employer ?

Jean-Pierre.

I started working here last week, and it�s a trainee position, where I am expected to under take a course which is involves doing these tedious tasks as part of the job, my boss is kinda my teacher, I should have said mentor though its still the same thing.

And doesn�t want me using awk or sed as they �promote laziness from programmer prospective� -_-

is it possible to redirect the string of permissions like rwxr-wr-- to a variable/tmp?

my condolences for a poor choice in employment...

i have to start someware :wink:

If you are not allowed to use the correct tools for the job then I suggest you kick up a fuss.
Unix utilities are there to be used not ignored because of someone's prejudices.
You have my sincere sympathies

i assume he is doing this, because he wants me to grasp some concepts, he did say i can use sed and awk once am confirtable doing stuff without them :rolleyes:

i have only being using unix for about 2 weeks now after all.

can we get to the problem in hand please :slight_smile:

and can the find function be used to display something like the 1st string of 10 characters from a line?

not exactly, but something to start with:

#!/bin/ksh

echo -n "please enter file name : "
read file

echo "      READ WRITE EXECUTE"
getfacl "${file}" | while IFS=':' read what junk perm
do
   case "${what}" in
      user|group|other)
             echo "${what} $(echo ${perm} | sed -e 's/[rwx]/ YES /g' -e 's/-/ NO /g')"
             ;;
   esac
done

that help me out a LOT, thank you, thank you all :b: