-
Notifications
You must be signed in to change notification settings - Fork 31
/
NameChange
executable file
·101 lines (84 loc) · 1.58 KB
/
NameChange
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/sh
# rename files
ERROR()
{
echo error: $*
exit 1
}
USAGE()
{
[ -z "$1" ] || echo error: $*
echo usage: $(basename "$0") '<options>'
echo ' --help -h this message'
echo ' --verbose -v more messages'
echo ' --dest=dir -d <dir> directory of files [image]'
echo ' --wiki -w rename pedia to wiki [default]'
echo ' --pedia -p rename wiki to pedia'
exit 1
}
# main program
# ------------
verbose=no
to=wiki
from=pedia
dest=image
getopt=/usr/local/bin/getopt
[ -x "${getopt}" ] || getopt=getopt
args=$(${getopt} -o hvd:wp --long=help,verbose,dest:,wiki,pedia -- "$@") || exit 1
# replace the arguments with the parsed values
eval set -- "${args}"
while :
do
case "$1" in
-v|--verbose)
verbose=yes
shift
;;
-w|--wiki)
to=wiki
from=pedia
shift
;;
-p|--pedia)
to=pedia
from=wiki
shift
;;
-d|--dest)
dest="$2"
shift 2
;;
--)
shift
break
;;
-h|--help)
USAGE
;;
*)
USAGE invalid option: $1
;;
esac
done
[ -d "${dest}" ] || USAGE not a directory: ${dest}
case "${verbose}" in
[yY]|[yY][eE][sS])
echo rename "${from}" to "${to}"
echo in directory: "${dest}"
;;
*)
;;
esac
find "${dest}" -name "${from}"\* | while read file junk
do
d=$(basename "${file}")
d=$(dirname "${file}")/${to}${d#${from}}
case "${verbose}" in
[yY]|[yY][eE][sS])
echo rename "${file}" to "${d}"
;;
*)
;;
esac
mv "${file}" "${d}"
done