tests: change `...' to '...' on lines not matching /[=\$]/
[coreutils.git] / tests / cp / perm
blob7a03400b0f20a91280cba6abb35ef65e3bb7cc91
1 #!/bin/sh
2 # Make sure the permission-preserving code in copy.c (mv, cp, install) works.
4 # Copyright (C) 2000, 2002, 2004-2012 Free Software Foundation, Inc.
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 . "${srcdir=.}/init.sh"; path_prepend_ ../src
20 print_ver_ cp mv
22 very_expensive_
24 umask 037
27 # Now, try it with 'mv', with combinations of --force, no-f and
28 # existing-destination and not.
29 for u in 31 37 2; do
30 echo umask: $u
31 umask $u
32 for cmd in mv 'cp -p' cp; do
33 for force in '' -f; do
34 for existing_dest in yes no; do
35 for g_perm in r w x rw wx xr rwx; do
36 for o_perm in r w x rw wx xr rwx; do
37 touch src || exit 1
38 chmod u=r,g=rx,o= src || exit 1
39 expected_perms=$(stat --format=%A src)
40 rm -f dest
41 test $existing_dest = yes && {
42 touch dest || exit 1
43 chmod u=rw,g=$g_perm,o=$o_perm dest || exit 1
45 $cmd $force src dest || exit 1
46 test "$cmd" = mv && test -f src && exit 1
47 test "$cmd" = cp && { test -f src || exit 1; }
48 actual_perms=$(stat --format=%A dest)
50 case "$cmd:$force:$existing_dest" in
51 cp:*:yes)
52 _g_perm=`echo rwx|sed 's/[^'$g_perm']/-/g'`
53 _o_perm=`echo rwx|sed 's/[^'$o_perm']/-/g'`
54 expected_perms=-rw-$_g_perm$_o_perm
56 cp:*:no)
57 test $u = 37 &&
58 expected_perms=`
59 echo $expected_perms | sed 's/.....$/-----/'
61 test $u = 31 &&
62 expected_perms=`
63 echo $expected_perms | sed 's/..\(..\).$/--\1-/'
66 esac
67 test _$actual_perms = _$expected_perms || exit 1
68 # Perform only one iteration when there's no existing destination.
69 test $existing_dest = no && break 3
70 done
71 done
72 done
73 done
74 done
75 done
77 Exit $fail