add kvpairs2td
[hband-tools.git] / user-tools / swap
blobd75b77b62747632819482935c0e5e2470777446b
1 #!/bin/bash
3 true <<EOF
4 =pod
6 =head1 NAME
8 swap - swaps two files' names
10 =cut
12 EOF
15 set -e
17 if [ $# -ne 2 ]
18 then
19 echo "swap: 2 arguments needed"
20 exit 1
22 if [ ! -e "$1" ]
23 then
24 echo "swap: file does not exist: $1"
25 exit 1
27 if [ ! -e "$2" ]
28 then
29 echo "swap: file does not exist: $2"
30 exit 1
34 TMP=`TMPDIR=. mktemp $([ -d "$1" ] && echo --directory) --dry-run -t .swap.XXXXXX`
36 if mv -Tv "$1" "$TMP"
37 then
38 if mv -Tv "$2" "$1"
39 then
40 if mv -Tv "$TMP" "$2"
41 then
42 exit 0
44 exit 4
46 exit 3
49 exit 2