-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction.sh
More file actions
67 lines (54 loc) · 1.36 KB
/
function.sh
File metadata and controls
67 lines (54 loc) · 1.36 KB
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
#!/usr/bin/env bash
# 一些简单的函数定义
# print something to stderr
function echoerr() {
cat <<<"$@" 1>&2
}
# judge a directory is exist.
# return 1 if it is exists else 0
function directory_exists() {
local directory_path=$1
if [ ! ${directory_path} ]; then
echoerr "The function usage is wrong. Please input the directory's path."
exit 2
fi
if [ -d "${directory_path}" ]; then
return 1
else
return 0
fi
}
# add a path to PYTHONPATH
# return 0 if success else exit
function add_python_path() {
local need_add_path=$1
if [ ! ${need_add_path} ]; then
echoerr "Please input the path you want to add .."
exit 2
fi
if [[ ${PYTHONPATH} != *"${need_add_path}"* ]]; then
export PYTHONPATH="${PYTHONPATH}:${need_add_path}"
fi
echo "Now, the python path is ${PYTHONPATH}."
return 0
}
# create a directory. if it exists, do nothing
function create_directory() {
local directory_path=$1
directory_exists ${directory_path}
if [ $? -eq 0 ]; then
mkdir ${directory_path}
return 0
fi
return 1
}
# create or clear a directory
function create_or_clear_directory() {
local directory_path=$1
directory_exists ${directory_path}
if [ $? -eq 0 ]; then
mkdir ${directory_path}
else
rm -rf ${directory_path}/*
fi
}