-
Notifications
You must be signed in to change notification settings - Fork 2
/
rename.sh
44 lines (23 loc) · 922 Bytes
/
rename.sh
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
#$1: source
source=$1
#$2: destination
destination=$2
# is the source, a file or folder?
type=$( [[ -f ${source} ]] && echo 'File') || $( [[ -d ${source} ]] && echo 'Folder' )
echo 'Renaming, '${type}' '${source}'; to '${destination}' ...'
function copy(){
$( [[ -f ${source} ]] && cp ${source} ${destination} ) || $( [[ -d ${source} ]] && cp -r ${source} ${destination} )
}
function remove(){
$( [[ -f ${source} ]] && rm ${source} ) || $( [[ -d ${source} ]] && rmdir -r ${source} )
}
function validate_renaming(){
if [[ -f ${destination} ]] || [[ -d ${destination} ]]; then
echo ${type}' '${source}', was renamed; to '${destination}' ... successfuly.'
else
echo ${type}' '${source}', was not renamed; to '${destination}' ... something; went wrong!'
$( [[ -f ${source} ]] || [[ -d ${source} ]] ) && echo ${type}' '${source}'; was not modified!'
fi
}
copy && remove && validate_renaming