cp,ln,mv: when skipping exit with nonzero status
[coreutils.git] / tests / mv / mv-n.sh
blobfbf571368dc65fa04e29c4f2ec403640e5887d94
1 #!/bin/sh
2 # Test whether mv -n works as documented (not overwrite target).
4 # Copyright (C) 2006-2023 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 | returns_ 1 mv -vin a b 2>/dev/null > out3 || fail=1
41 compare out3 out_empty || fail=1
43 # -n wins (as the last option)
44 touch a b || framework_failure_
45 echo y | returns_ 1 mv -vfn a b 2>/dev/null > out4 || fail=1
46 compare out4 out_empty || fail=1
48 # -n wins (as the last option)
49 touch a b || framework_failure_
50 echo y | returns_ 1 mv -vifn a b 2>/dev/null > out5 || fail=1
51 compare out5 out_empty || fail=1
53 # options --backup and --no-clobber are mutually exclusive
54 touch a || framework_failure_
55 returns_ 1 mv -bn a b 2>/dev/null || fail=1
57 Exit $fail