-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathextensionCaseChanger.sh
More file actions
executable file
·45 lines (37 loc) · 995 Bytes
/
Copy pathextensionCaseChanger.sh
File metadata and controls
executable file
·45 lines (37 loc) · 995 Bytes
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
#!/bin/bash
if [ -z $1 ]; then
echo "no case specified"
exit 1
else
if [ $1 == "upper" ] || [ $1 == "lower" ]; then
caseToUse=$1
else
echo "invalid case specified"
fi
fi
let counter=0
for loopFile in "$@"
do
if [ $counter -gt 0 ]; then
if [ -f $loopFile ]; then
fileToProcess=$loopFile
nameAndDot=`echo "$fileToProcess" | sed -e 's-\(.*\)\.\(.*\)-\1.-'`
extension=`echo "$fileToProcess" | sed -e 's-\(.*\)\.\(.*\)-\2-'`
if [ "$caseToUse" == "upper" ]; then
fixedExtension=`echo "$extension" | tr '[:lower:]' '[:upper:]'`
else
fixedExtension=`echo "$extension" | tr '[:upper:]' '[:lower:]'`
fi
targetFilename="${nameAndDot}${fixedExtension}"
if [ "$targetFilename" == "$fileToProcess" ]; then
echo "no rename needed for $fileToProcess..."
else
echo "renaming [$fileToProcess] to [$targetFilename]..."
mv "$fileToProcess" "$targetFilename"
fi
else
echo "invalid input file specified"
fi
fi
let counter=$counter+1
done