home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / shell / 3486 < prev    next >
Encoding:
Internet Message Format  |  1992-08-13  |  2.0 KB

  1. Path: sparky!uunet!cs.utexas.edu!sdd.hp.com!hplabs!ucbvax!mtxinu!sybase!hsc
  2. From: hsc@sybase.com (Howard Cohen)
  3. Newsgroups: comp.unix.shell
  4. Subject: Re: Octal chmod status
  5. Message-ID: <22411@sybase.sybase.com>
  6. Date: 14 Aug 92 00:30:18 GMT
  7. References: <17205.2219215579@kcbbs.gen.nz> <MERLYN.92Aug9093023@romulus.reed.edu>
  8. Sender: news@Sybase.COM
  9. Organization: Sybase, Inc.
  10. Lines: 48
  11.  
  12. In article <MERLYN.92Aug9093023@romulus.reed.edu> merlyn@romulus.reed.edu (Randal L. Schwartz) writes:
  13. >In article <17205.2219215579@kcbbs.gen.nz> Rowan_Smith@kcbbs.gen.nz (Rowan Smith) writes:
  14. >   Can somebody please give me a command/method by which I can get the 
  15. >   octal equivilant of rwxrwxr-x etc so that I can do the following.
  16. >
  17. >   set perm = 'octalconv <filename>'
  18. >
  19. >   is ($perm != 0511) then
  20. >      etc....
  21.  
  22. Well, here's a brute force method I've used successfully.  This can
  23. certainly be done in a smarter way, and it could also be made to understand
  24. things like the sticky bit, the setuid bit, the setgid bit, etc.  I didn't
  25. need that stuff though because I knew the files were source code.
  26.  
  27. ------------------------- cut here --------------------------------------
  28.  
  29. #!/bin/sh
  30.  
  31. LSPERMS=`ls -l "$1" | sed -e "s:^\([^  ][^     ]*\).*:\1:"`
  32. USR=`echo $LSPERMS X| sed -e "s:.\(...\).*:\1:"`
  33. GRP=`echo $LSPERMS X| sed -e "s:....\(...\).*:\1:"`
  34. OTH=`echo $LSPERMS X| sed -e "s:.......\(...\).*:\1:"`
  35.  
  36. PERMS=""
  37. for elem in $USR $GRP $OTH
  38. do
  39.      case "$elem" in
  40.      ---)    PERMS="${PERMS}0";;
  41.      --x)    PERMS="${PERMS}1";;
  42.      -w-)    PERMS="${PERMS}2";;
  43.      -wx)    PERMS="${PERMS}3";;
  44.      r--)    PERMS="${PERMS}4";;
  45.      r-x)    PERMS="${PERMS}5";;
  46.      rw-)    PERMS="${PERMS}6";;
  47.      rwx)    PERMS="${PERMS}7";;
  48.      esac
  49. done
  50.  
  51. echo $PERMS
  52.  
  53. ------------------------- cut here --------------------------------------
  54.  
  55.     Howard
  56. -------------------------------------------------------------------------------
  57.   Howard "I wood if I could" Cohen
  58.   hsc@sybase.com  {pacbell,pyramid,sun,{uunet,ucbvax}!mtxinu}!sybase!hsc
  59.   Sybase, Inc.    6475 Christie Avenue, Emeryville, CA 94608, 510-596-3406 
  60.