mv-n.sh 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/bin/sh
  2. # Test whether mv -n works as documented (not overwrite target).
  3. # Copyright (C) 2006-2018 Free Software Foundation, Inc.
  4. # This program is free software: you can redistribute it and/or modify
  5. # it under the terms of the GNU General Public License as published by
  6. # the Free Software Foundation, either version 3 of the License, or
  7. # (at your option) any later version.
  8. # This program is distributed in the hope that it will be useful,
  9. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. # GNU General Public License for more details.
  12. # You should have received a copy of the GNU General Public License
  13. # along with this program. If not, see <https://www.gnu.org/licenses/>.
  14. . "${srcdir=.}/tests/init.sh"; path_prepend_ ./src
  15. print_ver_ mv
  16. # test miscellaneous combinations of -f -i -n parameters
  17. touch a b || framework_failure_
  18. echo "renamed 'a' -> 'b'" > out_move
  19. > out_empty
  20. # ask for overwrite, answer no
  21. touch a b || framework_failure_
  22. echo n | mv -vi a b 2>/dev/null > out1 || fail=1
  23. compare out1 out_empty || fail=1
  24. # ask for overwrite, answer yes
  25. touch a b || framework_failure_
  26. echo y | mv -vi a b 2>/dev/null > out2 || fail=1
  27. compare out2 out_move || fail=1
  28. # -n wins (as the last option)
  29. touch a b || framework_failure_
  30. echo y | mv -vin a b 2>/dev/null > out3 || fail=1
  31. compare out3 out_empty || fail=1
  32. # -n wins (as the last option)
  33. touch a b || framework_failure_
  34. echo y | mv -vfn a b 2>/dev/null > out4 || fail=1
  35. compare out4 out_empty || fail=1
  36. # -n wins (as the last option)
  37. touch a b || framework_failure_
  38. echo y | mv -vifn a b 2>/dev/null > out5 || fail=1
  39. compare out5 out_empty || fail=1
  40. # options --backup and --no-clobber are mutually exclusive
  41. touch a || framework_failure_
  42. returns_ 1 mv -bn a b 2>/dev/null || fail=1
  43. Exit $fail