-
Notifications
You must be signed in to change notification settings - Fork 349
/
Copy pathhelpers.sh
46 lines (42 loc) · 1 KB
/
helpers.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
#!/bin/sh
# Useful string manipulation functions, leaving in for posterity
# https://stackoverflow.com/a/8811800
# contains(string, substring)
#
# Returns 0 if the specified string contains the specified substring,
# otherwise returns 1.
contains()
{
string="$1"
substring="$2"
if [ "${string#*"$substring"}" != "$string" ]; then
echo 0 # $substring is in $string
else
echo 1 # $substring is not in $string
fi
}
setenvStr()
{
# Changing IFS produces the most consistent results
tmpIFS=$IFS
IFS=","
string="$1"
for s in $string; do
if [ ! -z $s ]; then
eval "echo export \"$s\""
eval "export \"$s\""
fi
done
IFS=$tmpIFS
}
banner()
{
lengthBanner=$1
shift
# https://www.shellscript.sh/examples/banner/
printf "#%${lengthBanner}s#\n" | tr " " "="
printf "# %-$(( ${lengthBanner} - 2 ))s #\n" "`date`"
printf "# %-$(( ${lengthBanner} - 2 ))s #\n" " "
printf "# %-$(( ${lengthBanner} - 2 ))s #\n" "$*"
printf "#%${lengthBanner}s#\n" | tr " " "="
}