Got stuck so plz help

I'm having problem writing a shell script using bash that takes a file as an argument. The script should be able to determine what permissions the owner, group and everybody has for the file passed in.

could anyone plz help me out.

ls -l "$1" | awk '{print $1}' | sed 's/^.//'

or if you need it with description:

script.ksh

ls -l $1  | awk '{print $1}' | sed 's/^.//' | sed 's/\(^...\)/owner:\1 group:/;s/\(...$\)/ others:\1/'

#script.ksh /tmp/test
owner:rw- group:r-- others:r--

dirty but it's working :slight_smile:

#!/bin/sh

if [ $# -ne 1 ]; then
        echo "Usage: $0 yourfilename"
 exit 127
fi

ls -al $1 | cut -d" " -f1
set -- `ls -l "$1"`
perms=${1#?}
uperm=${perms%??????}
temp=${perms#???}
gperm=${temp%???}
operm=${temp#???}


That will work in any POSIX shell (including bash). It can be written more succinctly in bash (this also works in ksh93):

set -- `ls -l "$1"`
uperm=${1:1:3}
gperm=${1:4:3}
operm=${1:7:3}