Tizen 2.0 Release
[external/tizen-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 # Copyright (C) 2000, 2001, 2006, 2007 Free Software Foundation, Inc.
6
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
11
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 # GNU General Public License for more details.
16
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
20 # 02110-1301, USA.
21
22 if test "$VERBOSE" = yes; then
23   set -x
24   mv --version
25   cp --version
26 fi
27
28 . $srcdir/../envvar-check
29
30 # Make sure we get English translations.
31 . $srcdir/../lang-default
32
33 PRIV_CHECK_ARG=require-non-root . $srcdir/../priv-check
34
35 pwd=`pwd`
36 tmp=cp-mv-if-$$
37 trap 'status=$?; cd "$pwd" && rm -rf $tmp && exit $status' 0
38 trap 'exit $?' 1 2 13 15
39
40 framework_failure=0
41 mkdir $tmp || framework_failure=1
42 cd $tmp || framework_failure=1
43
44 for i in a b c d e f g h; do
45   echo $i > $i || framework_failure=1
46 done
47 chmod 0 b d f h || framework_failure=1
48 echo y > y || framework_failure=1
49
50 if test $framework_failure = 1; then
51   echo 'failure in testing framework'
52   exit 1
53 fi
54
55 fail=0
56 mv -if a b || fail=1
57 mv -fi c d < y >/dev/null 2>&1 || fail=1
58
59 # Before 4.0s, this would not prompt.
60 cp -if e f < y > out 2>&1 || fail=1
61
62 # Make sure out contains the prompt.
63 case "`cat out`" in
64   "cp: try to overwrite \`f', overriding mode 0000 (---------)?"*) ;;
65   *) fail=1 ;;
66 esac
67
68 test -f e || fail=1
69 test -f f || fail=1
70 cmp e f || fail=1
71
72 cp -fi g h < y > out 2>&1 || fail=1
73 test -f g || fail=1
74 test -f h || fail=1
75 cmp g h || fail=1
76
77 exit $fail