82cce5710f3350aa3b8463f4316f06e4b748a4dc
[platform/upstream/coreutils.git] / tests / mv / i-2
1 #!/bin/sh
2 # Test both cp and mv for their behavior with -if and -fi
3 # The standards (POSIX and SuS) dictate annoyingly inconsistent behavior.
4
5 if test "$VERBOSE" = yes; then
6   set -x
7   mv --version
8   cp --version
9 fi
10
11 . $srcdir/../envvar-check
12
13 # Make sure we get English translations.
14 . $srcdir/../lang-default
15
16 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
17
18 pwd=`pwd`
19 tmp=cp-mv-if-$$
20 trap 'status=$?; cd $pwd; rm -rf $tmp && exit $status' 0
21 trap 'exit $?' 1 2 13 15
22
23 framework_failure=0
24 mkdir $tmp || framework_failure=1
25 cd $tmp || framework_failure=1
26
27 for i in a b c d e f g h; do
28   echo $i > $i || framework_failure=1
29 done
30 chmod 0 b d f h || framework_failure=1
31 echo y > y || framework_failure=1
32
33 if test $framework_failure = 1; then
34   echo 'failure in testing framework'
35   exit 1
36 fi
37
38 fail=0
39 mv -if a b || fail=1
40 mv -fi c d < y >/dev/null 2>&1 || fail=1
41
42 # Before 4.0s, this would not prompt.
43 cp -if e f < y > out 2>&1 || fail=1
44
45 # Make sure out contains the prompt.
46 case "`cat out`" in
47   "cp: overwrite \`f', overriding mode 0000?"*) ;;
48   *) fail=1 ;;
49 esac
50
51 test -f e || fail=1
52 test -f f || fail=1
53 cmp e f || fail=1
54
55 cp -fi g h < y > out 2>&1 || fail=1
56 test -f g || fail=1
57 test -f h || fail=1
58 cmp g h || fail=1
59
60 exit $fail