forked from Jiahui17/dynamatic-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.sh
More file actions
34 lines (30 loc) · 722 Bytes
/
utils.sh
File metadata and controls
34 lines (30 loc) · 722 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
#!/bin/bash
# Prints some information to stdout.
# $1: the text to print
echo_info() {
echo "[INFO] $1"
}
# Prints a fatal error message to stdout.
# $1: the text to print
echo_fatal() {
echo "[FATAL] $1"
}
# Exits the script with a fatal error message if the last command that was
# called before this function failed, otherwise optionally prints an information
# message.
# $1: fatal error message
# $2: [optional] information message
exit_on_fail() {
if [[ $? -ne 0 ]]; then
if [[ ! -z $1 ]]; then
echo_fatal "$1"
exit 1
fi
echo_fatal "Failed!"
exit 1
else
if [[ ! -z $2 ]]; then
echo_info "$2"
fi
fi
}