source: trunk/essentials/app-shells/bash/examples/scripts/showperm.bash@ 3247

Last change on this file since 3247 was 3228, checked in by bird, 19 years ago

bash 3.1

File size: 1.2 KB
Line 
1#Newsgroups: comp.unix.shell
2#From: [email protected] (Geoff Clare)
3#Subject: Re: Determining permissions on a file
4#Message-ID: <[email protected]>
5#Date: Fri, 10 May 1996 17:23:56 GMT
6
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...
10#
11#
12# Converted to Bash v2 syntax by Chet Ramey <[email protected]>
13#
14# usage: showperm modestring
15#
16# example: showperm '-rwsr-x--x'
17#
18
19[ -z "$1" ] && {
20 echo "showperm: usage: showperm modestring" >&2
21 exit 2
22}
23
24tmode="$1"
25
26typeset -i omode sbits
27typeset pmode
28
29# check for set-uid, etc. bits
30sbits=0
31case $tmode in
32???[sS]*) (( sbits += 8#4000 )) ;; # set-uid
33??????[sSl]*) (( sbits += 8#2000 )) ;; # set-gid or mand. lock
34?????????[tT]*) (( sbits += 8#1000 )) ;; # sticky
35esac
36
37omode=0
38while :