1 #Newsgroups: comp.unix.shell
2 #From: gwc@root.co.uk (Geoff Clare)
3 #Subject: Re: Determining permissions on a file
4 #Message-ID: <Dr79nw.DtL@root.co.uk>
5 #Date: Fri, 10 May 1996 17:23:56 GMT
7 #Here's a bit of Korn shell that converts the symbolic permissions produced
8 #by "ls -l" into octal, using only shell builtins. How to create a script
9 #combining this with an "ls -l" is left as an exercise...
12 # Converted to Bash v2 syntax by Chet Ramey <chet@po.cwru.edu>
14 # usage: showperm modestring
16 # example: showperm '-rwsr-x--x'
20 echo "showperm: usage: showperm modestring" >&2
26 typeset
-i omode sbits
29 # check for set-uid, etc. bits
32 ???
[sS
]*) (( sbits
+= 8#4000 )) ;; # set-uid
33 ??????
[sSl
]*) (( sbits
+= 8#2000 )) ;; # set-gid or mand. lock
34 ?????????
[tT
]*) (( sbits
+= 8#1000 )) ;; # sticky
43 [-STl]*) (( omode
*= 2 )) ;;
44 [rwxst
]*) (( omode
= omode
*2 + 1 )) ;;
45 *) echo "$0: first letter of \"$tmode\" is unrecognized" >&2