+1  A: 

I'd just use stat -c %a and process that instead.

Ignacio Vazquez-Abrams
Just note that stat isn't portable (BSD doesn't have it I think)
Daenyth
@Ignacio Vazquez-Abrams -- Could you be a bit more precise.I'm a novice,thank you.
Pavitar
@Pavitar: Try yourself first, *then* ask further questions.
Ignacio Vazquez-Abrams
@Ignacio Vazquez-Abrams -- ok. thank you
Pavitar
A: 

Hello,

an exemple using awk (easily adaptable to your program)

ll |awk '{
             rights=substr($1, 2, 3);
             sub(/r/, "READ ", rights);
             sub(/w/, "WRITE ", rights);
             sub(/x/, "EXECUTE ", rights);
             print rights $3
          }'

Explanations :

rights=substr($1, 2, 3);

$1 contains rights of your program and we only takes the 3 first rights (user one)

sub(/r/, "READ ", rights);

Substiture "r" with READ in rights (and so on).

print rights $3

Print rights (substituated) and $3 that contains the user name.

Arnaud F.
+4  A: 

Too complicated. You don't have to rely on ls at all:

#!/bin/bash

if [[ $# -lt 1 ]]; then
    echo "USAGE: $(basename "$0") filename ..."
    exit 1
fi

exit_status=0

for file in "$@"; do
    if [[ ! -f "$file" ]]; then
        echo "not a file: $file" >&2
        exit_status=$(( exit_status + 1 ))
        continue
    fi

    echo "$file:"
    echo "User"   

    [[ -r "$file" ]] && echo "READ"
    [[ -w "$file" ]] && echo "WRITE"
    [[ -x "$file" ]] && echo "EXECUTE"
done

exit $exit_status
glenn jackman
A: 

This served my purpose,I separated the first condition into a different case-statement.:

#!/bin/bash

if [ $# -lt 1 ];then
    echo "USAGE: $0 file-name"
    exit 1
fi


ls -l $1 | cut -c1-4 | tr "\012" "." > fp


i=1
while(($i == 1))
do
    p=`cat fp | cut -c$i`

    case $p in

    [dbsplc] | t) echo "not a file";
        exit 1;;
esac

     echo "User"
    ((++i))
done



while(($i <= 4))
do
    p=`cat fp | cut -c$i`

    case $p in
    r) echo "READ";;
    w) echo "WRITE";;
    x) echo "EXECUTE";;

    esac

    ((++i))
done


exit 0
Pavitar
There's absolutely no reason to use the first `while` - it's always going to be executed and only once. The second `while` should be a `for` loop instead: `for i in {2..4}`. It's not necessary to use `cat`. In fact, the temporary file and all the external utilities are also unnecessary since you can save the data in a variable and use Bash's substring parsing to pick out the individual characters `${var:i:1}`. However, glenn jackman's answer is the way to go.
Dennis Williamson
@ Dennis Williamson -- OK.I'm a novice.So I did what I thought was simple for me to understand.I will surely try Glenn Jackman's approach as well.Thankyou for the tips ..
Pavitar