Skip to content

Commit 02fd2cc

Browse files
author
dvmorris
committed
test bash script for redmine code review tool, refs #1
1 parent ddedc15 commit 02fd2cc

File tree

1 file changed

+94
-0
lines changed

1 file changed

+94
-0
lines changed

topmodx/tmp/test-script.sh

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
#!/bin/sh
2+
# renna: rename multiple files according to several rules
3+
# written by felix hudson Jan - 2000
4+
5+
#first check for the various 'modes' that this program has
6+
#if the first ($1) condition matches then we execute that portion of the
7+
#program and then exit
8+
9+
# check for the prefix condition
10+
if [ $1 = p ]; then
11+
12+
#we now get rid of the mode ($1) variable and prefix ($2)
13+
prefix=$2 ; shift ; shift
14+
15+
# a quick check to see if any files were given
16+
# if none then its better not to do anything than rename some non-existent
17+
# files!!
18+
19+
if [$1 = ]; then
20+
echo "no files given"
21+
exit 0
22+
fi
23+
24+
# this for loop iterates through all of the files that we gave the program
25+
# it does one rename per file given
26+
for file in $*
27+
do
28+
mv ${file} $prefix$file
29+
done
30+
31+
#we now exit the program
32+
exit 0
33+
fi
34+
35+
# check for a suffix rename
36+
# the rest of this part is virtually identical to the previous section
37+
# please see those notes
38+
if [ $1 = s ]; then
39+
suffix=$2 ; shift ; shift
40+
41+
if [$1 = ]; then
42+
echo "no files given"
43+
exit 0
44+
fi
45+
46+
for file in $*
47+
do
48+
mv ${file} $file$suffix
49+
done
50+
51+
exit 0
52+
fi
53+
54+
# check for the replacement rename
55+
if [ $1 = r ]; then
56+
57+
shift
58+
59+
# i included this bit as to not damage any files if the user does not specify
60+
# anything to be done
61+
# just a safety measure
62+
63+
if [ $# -lt 3 ] ; then
64+
echo "usage: renna r [expression] [replacement] files... "
65+
exit 0
66+
fi
67+
68+
# remove other information
69+
OLD=$1 ; NEW=$2 ; shift ; shift
70+
71+
# this for loop iterates through all of the files that we give the program
72+
# it does one rename per file given using the program 'sed'
73+
# this is a sinple command line program that parses standard input and
74+
# replaces a set expression with a give string
75+
# here we pass it the file name ( as standard input) and replace the nessesary
76+
# text
77+
78+
for file in $*
79+
do
80+
new=`echo ${file} | sed s/${OLD}/${NEW}/g`
81+
mv ${file} $new
82+
done
83+
exit 0
84+
fi
85+
86+
# if we have reached here then nothing proper was passed to the program
87+
# so we tell the user how to use it
88+
echo "usage;"
89+
echo " renna p [prefix] files.."
90+
echo " renna s [suffix] files.."
91+
echo " renna r [expression] [replacement] files.."
92+
exit 0
93+
94+
# done!

0 commit comments

Comments
 (0)