cp: with --no-preserve=mode ensure set-group-ID bits maintained on dirs
[coreutils.git] / tests / mv / mv-n.sh
blob627c97aee5cc0bb67ae2543388ac87c0240c2127
1 #!/bin/sh
2 # Test whether mv -n works as documented (not overwrite target).
4 # Copyright (C) 2006-2024 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 <https://www.gnu.org/licenses/>.
19 . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
20 print_ver_ mv
23 # test miscellaneous combinations of -f -i -n parameters
24 touch a b || framework_failure_
25 echo "renamed 'a' -> 'b'" > out_move
26 > out_empty
28 # ask for overwrite, answer no
29 touch a b || framework_failure_
30 echo n | returns_ 1 mv -vi a b 2>/dev/null > out1 || fail=1
31 compare out1 out_empty || fail=1
33 # ask for overwrite, answer yes
34 touch a b || framework_failure_
35 echo y | mv -vi a b 2>/dev/null > out2 || fail=1
36 compare out2 out_move || fail=1
38 # -n wins (as the last option)
39 touch a b || framework_failure_
40 echo y | mv -vin a b 2>/dev/null > out3 || fail=1
41 compare out3 out_empty || fail=1
43 # -n wins (non verbose)
44 touch a b || framework_failure_
45 echo y | mv -in a b 2>err3 > out3 || fail=1
46 compare out3 out_empty || fail=1
47 compare /dev/null err3 || fail=1
49 # -n wins (as the last option)
50 touch a b || framework_failure_
51 echo y | mv -vfn a b 2>/dev/null > out4 || fail=1
52 compare out4 out_empty || fail=1
54 # -n wins (as the last option)
55 touch a b || framework_failure_
56 echo y | mv -vifn a b 2>/dev/null > out5 || fail=1
57 compare out5 out_empty || fail=1
59 # options --backup and --no-clobber are mutually exclusive
60 touch a || framework_failure_
61 returns_ 1 mv -bn a b 2>/dev/null || fail=1
62 # options --backup and --update=none{,-fail} are mutually exclusive
63 returns_ 1 mv -b --update=none a b 2>/dev/null || fail=1
64 returns_ 1 mv -b --update=none-fail a b 2>/dev/null || fail=1
66 Exit $fail