Adjust a seq subtest not to depend on the vagaries of floating point.
[platform/upstream/coreutils.git] / 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 3 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, see <http://www.gnu.org/licenses/>.
20
21 case $# in
22   1) rwx=$1;;
23   *) echo "$0: wrong number of arguments" 1>&2
24     echo "Usage: $0 ls-style-mode-string" 1>&2
25     exit 1;;
26 esac
27
28 case $rwx in
29   [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]) ;;
30   [ld-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxsS-][rwx-][rwx-][rwxtT-]+) ;;
31   *) echo "$0: invalid mode string: $rwx" 1>&2; exit 1;;
32 esac
33
34 # Perform these conversions:
35 # S  s
36 # s  xs
37 # T  t
38 # t  xt
39 # The `T' and `t' ones are only valid for `other'.
40 s='s/S/@/;s/s/x@/;s/@/s/'
41 t='s/T/@/;s/t/x@/;s/@/t/'
42
43 u=`echo $rwx|sed 's/^.\(...\).*/,u=\1/;s/-//g;s/^,u=$//;'$s`
44 g=`echo $rwx|sed 's/^....\(...\).*/,g=\1/;s/-//g;s/^,g=$//;'$s`
45 o=`echo $rwx|sed 's/^.......\(...\).*/,o=\1/;s/-//g;s/^,o=$//;'$s';'$t`
46 echo "=$u$g$o"
47 exit 0