*** empty log message ***
[coreutils.git] / tests / rwx-to-mode
blob740e77a0e5590b9d0223cfd6de4b0bdff2b93c5c
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).
6 case $# in
7 1) rwx=$1;;
8 *) echo "$0: wrong number of arguments" 1>&2
9 echo "Usage: $0 ls-style-mode-string" 1>&2
10 exit 1;;
11 esac
13 case $rwx in
14 [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]) ;;
15 *) echo "$0: invalid mode string: $rwx" 1>&2; exit 1;;
16 esac
18 # Perform these conversions:
19 # S s
20 # s xs
21 # T t
22 # t xt
23 # The `T' and `t' ones are only valid for `other'.
24 s='s/S/@/;s/s/x@/;s/@/s/'
25 t='s/T/@/;s/t/x@/;s/@/t/'
27 u=`echo $rwx|sed 's/^.\(...\).*/,u=\1/;s/-//g;s/^,u=$//;'$s`
28 g=`echo $rwx|sed 's/^....\(...\).*/,g=\1/;s/-//g;s/^,g=$//;'$s`
29 o=`echo $rwx|sed 's/^.......\(...\).*/,o=\1/;s/-//g;s/^,o=$//;'$s';'$t`
30 echo "=$u$g$o"
31 exit 0