home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!hplabs!ucbvax!mtxinu!sybase!hsc
- From: hsc@sybase.com (Howard Cohen)
- Newsgroups: comp.unix.shell
- Subject: Re: Octal chmod status
- Message-ID: <22411@sybase.sybase.com>
- Date: 14 Aug 92 00:30:18 GMT
- References: <17205.2219215579@kcbbs.gen.nz> <MERLYN.92Aug9093023@romulus.reed.edu>
- Sender: news@Sybase.COM
- Organization: Sybase, Inc.
- Lines: 48
-
- In article <MERLYN.92Aug9093023@romulus.reed.edu> merlyn@romulus.reed.edu (Randal L. Schwartz) writes:
- >In article <17205.2219215579@kcbbs.gen.nz> Rowan_Smith@kcbbs.gen.nz (Rowan Smith) writes:
- > Can somebody please give me a command/method by which I can get the
- > octal equivilant of rwxrwxr-x etc so that I can do the following.
- >
- > set perm = 'octalconv <filename>'
- >
- > is ($perm != 0511) then
- > etc....
-
- Well, here's a brute force method I've used successfully. This can
- certainly be done in a smarter way, and it could also be made to understand
- things like the sticky bit, the setuid bit, the setgid bit, etc. I didn't
- need that stuff though because I knew the files were source code.
-
- ------------------------- cut here --------------------------------------
-
- #!/bin/sh
-
- LSPERMS=`ls -l "$1" | sed -e "s:^\([^ ][^ ]*\).*:\1:"`
- USR=`echo $LSPERMS X| sed -e "s:.\(...\).*:\1:"`
- GRP=`echo $LSPERMS X| sed -e "s:....\(...\).*:\1:"`
- OTH=`echo $LSPERMS X| sed -e "s:.......\(...\).*:\1:"`
-
- PERMS=""
- for elem in $USR $GRP $OTH
- do
- case "$elem" in
- ---) PERMS="${PERMS}0";;
- --x) PERMS="${PERMS}1";;
- -w-) PERMS="${PERMS}2";;
- -wx) PERMS="${PERMS}3";;
- r--) PERMS="${PERMS}4";;
- r-x) PERMS="${PERMS}5";;
- rw-) PERMS="${PERMS}6";;
- rwx) PERMS="${PERMS}7";;
- esac
- done
-
- echo $PERMS
-
- ------------------------- cut here --------------------------------------
-
- Howard
- -------------------------------------------------------------------------------
- Howard "I wood if I could" Cohen
- hsc@sybase.com {pacbell,pyramid,sun,{uunet,ucbvax}!mtxinu}!sybase!hsc
- Sybase, Inc. 6475 Christie Avenue, Emeryville, CA 94608, 510-596-3406
-