(linenum→info "unix/slp.c:2238")

coreutils/6.9/tests/rwx-to-mode

    1: #!/bin/sh
    2: # Convert an ls-style permission string, like drwxr----x and -rw-r-x-wx
    3: # to the equivalent chmod --mode (-m) argument, (=,u=rwx,g=r,o=x and
    4: # =,u=rw,g=rx,o=wx).  Ignore ACLs.
    5: 
    6: # Copyright (C) 2000, 2005 Free Software Foundation, Inc.
    7: 
    8: # This program is free software; you can redistribute it and/or modify
    9: # it under the terms of the GNU General Public License as published by
   10: # the Free Software Foundation; either version 2 of the License, or
   11: # (at your option) any later version.
   12: 
   13: # This program is distributed in the hope that it will be useful,
   14: # but WITHOUT ANY WARRANTY; without even the implied warranty of
   15: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   16: # GNU General Public License for more details.
   17: 
   18: # You should have received a copy of the GNU General Public License
   19: # along with this program; if not, write to the Free Software
   20: # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
   21: # 02110-1301, USA.
   22: 
   23: case $# in
   24:   1) rwx=$1;;
   25:   *) echo "$0: wrong number of arguments" 1>&2
   26:     echo "Usage: $0 ls-style-mode-string" 1>&2
   27:     exit 1;;
   28: esac
   29: 
   30: case $rwx in
   31:   [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]) ;;
   32:   [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]+) ;;
   33:   *) echo "$0: invalid mode string: $rwx" 1>&2; exit 1;;
   34: esac
   35: 
   36: # Perform these conversions:
   37: # S  s
   38: # s  xs
   39: # T  t
   40: # t  xt
   41: # The `T' and `t' ones are only valid for `other'.
   42: s='s/S/@/;s/s/x@/;s/@/s/'
   43: t='s/T/@/;s/t/x@/;s/@/t/'
   44: 
   45: u=`echo $rwx|sed 's/^.\(...\).*/,u=\1/;s/-//g;s/^,u=$//;'$s`
   46: g=`echo $rwx|sed 's/^....\(...\).*/,g=\1/;s/-//g;s/^,g=$//;'$s`
   47: o=`echo $rwx|sed 's/^.......\(...\).*/,o=\1/;s/-//g;s/^,o=$//;'$s';'$t`
   48: echo "=$u$g$o"
   49: exit 0
Syntax (Markdown)