home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.shell
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!nucsrl!ddsw1!dattier
- From: dattier@ddsw1.mcs.com (David W. Tamkin)
- Subject: Re: Octal chmod status
- Message-ID: <1992Aug16.025615.23956@ddsw1.mcs.com>
- Organization: Contributor Account at ddsw1, Chicago, Illinois 60657
- References: <17205.2219215579@kcbbs.gen.nz> <MERLYN.92Aug9093023@romulus.reed.edu> <22411@sybase.sybase.com>
- Date: Sun, 16 Aug 1992 02:56:15 GMT
- X-Disclaimer: Material posted in this article is the sole responsibility of
- the poster and does not represent MCSNet or the system owners.
- Lines: 41
-
- hsc@sybase.com (Howard Cohen) wrote in <22411@sybase.sybase.com>:
-
- | 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:"`
-
- How about this to replace those four lines:
-
- eval `ls -ld "$1" | sed 's/^.\(...\)\(...\)\(...\).*/USR=\1 GRP=\2 OTH=\3/'`
-
- | 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
-
- The rest is pretty darn clever.
-
- David W. Tamkin Box 59297 Northtown Station, Illinois 60659-0297
- dattier@ddsw1.mcs.com CompuServe: 73720,1570 MCI Mail: 426-1818
-