-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmy-utils.sh
54 lines (50 loc) · 866 Bytes
/
my-utils.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
45
46
47
48
49
50
51
52
53
54
create_dir() {
for arg in $@
do
if [[ ! -d $arg ]]
then
mkdir -p $arg
fi
done
}
create_file() {
for arg in $@
do
if [[ ! -f $arg ]]
then
create_dir ${arg%/*}
touch $arg
fi
done
}
check_delete() {
for arg in $@
do
if [[ -d $arg ]]
then
rm -rf $arg
elif [[ -f $arg ]]
then
rm -f $arg
fi
done
}
check_copy() {
last_str=${1: -1}
if [[ $last_str == '/' ]]
then
src_path=${1%?}
else
src_path=$1
fi
base_path=${src_path%/*}
if [[ -d $src_path ]]
then
create_dir $2/$base_path
cp -r $src_path $2/$base_path/
elif [[ -f $src_path ]]
then
create_dir $2/$base_path
cp $src_path $2/$base_path/
fi
}