repo.or.cz
/
hband-tools.git
/
blob
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
log
|
graphiclog1
|
graphiclog2
|
commit
|
commitdiff
|
tree
|
refs
|
edit
|
fork
blame
|
history
|
raw
|
HEAD
add kvpairs2td
[hband-tools.git]
/
user-tools
/
swap
blob
d75b77b62747632819482935c0e5e2470777446b
1
#!/bin/bash
2
3
true
<<EOF
4
=pod
5
6
=head1 NAME
7
8
swap - swaps two files' names
9
10
=cut
11
12
EOF
13
14
15
set -e
16
17
if
[
$#
-ne
2
]
18
then
19
echo
"swap: 2 arguments needed"
20
exit
1
21
fi
22
if
[ !
-e
"
$1
"
]
23
then
24
echo
"swap: file does not exist:
$1
"
25
exit
1
26
fi
27
if
[ !
-e
"
$2
"
]
28
then
29
echo
"swap: file does not exist:
$2
"
30
exit
1
31
fi
32
33
34
TMP
=
`TMPDIR=. mktemp $([ -d "
$1
" ] && echo --directory) --dry-run -t .swap.XXXXXX`
35
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
43
fi
44
exit
4
45
fi
46
exit
3
47
fi
48
49
exit
2