home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3496 < prev    next >
Encoding:
Text File  |  1992-08-15  |  2.0 KB  |  54 lines

  1. Newsgroups: comp.unix.shell
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!news.acns.nwu.edu!nucsrl!ddsw1!dattier
  3. From: dattier@ddsw1.mcs.com (David W. Tamkin)
  4. Subject: Re: Octal chmod status
  5. Message-ID: <1992Aug16.025615.23956@ddsw1.mcs.com>
  6. Organization: Contributor Account at ddsw1, Chicago, Illinois  60657
  7. References: <17205.2219215579@kcbbs.gen.nz> <MERLYN.92Aug9093023@romulus.reed.edu> <22411@sybase.sybase.com>
  8. Date: Sun, 16 Aug 1992 02:56:15 GMT
  9. X-Disclaimer:  Material posted in this article is the sole responsibility of
  10.                 the poster and does not represent MCSNet or the system owners.
  11. Lines: 41
  12.  
  13. hsc@sybase.com (Howard Cohen) wrote in <22411@sybase.sybase.com>:
  14.  
  15. | Well, here's a brute force method I've used successfully.  This can
  16. | certainly be done in a smarter way, and it could also be made to understand
  17. | things like the sticky bit, the setuid bit, the setgid bit, etc.  I didn't
  18. | need that stuff though because I knew the files were source code.
  19. | ------------------------- cut here --------------------------------------
  20. | #!/bin/sh
  21. | LSPERMS=`ls -l "$1" | sed -e "s:^\([^  ][^     ]*\).*:\1:"`
  22. | USR=`echo $LSPERMS X| sed -e "s:.\(...\).*:\1:"`
  23. | GRP=`echo $LSPERMS X| sed -e "s:....\(...\).*:\1:"`
  24. | OTH=`echo $LSPERMS X| sed -e "s:.......\(...\).*:\1:"`
  25.  
  26. How about this to replace those four lines:
  27.  
  28. eval `ls -ld "$1" | sed 's/^.\(...\)\(...\)\(...\).*/USR=\1 GRP=\2 OTH=\3/'`
  29.  
  30. | PERMS=""
  31. | for elem in $USR $GRP $OTH
  32. | do
  33. |      case "$elem" in
  34. |        ---)    PERMS="${PERMS}0";;
  35. |        --x)    PERMS="${PERMS}1";;
  36. |        -w-)    PERMS="${PERMS}2";;
  37. |        -wx)    PERMS="${PERMS}3";;
  38. |        r--)    PERMS="${PERMS}4";;
  39. |        r-x)    PERMS="${PERMS}5";;
  40. |        rw-)    PERMS="${PERMS}6";;
  41. |        rwx)    PERMS="${PERMS}7";;
  42. |      esac
  43. | done
  44. | echo $PERMS
  45.  
  46. The rest is pretty darn clever.
  47.  
  48. David W. Tamkin   Box 59297   Northtown Station, Illinois  60659-0297
  49. dattier@ddsw1.mcs.com    CompuServe: 73720,1570    MCI Mail: 426-1818
  50.