-
Notifications
You must be signed in to change notification settings - Fork 0
/
Introduction_to_Bash_Scripting.sh
60 lines (39 loc) · 1.36 KB
/
Introduction_to_Bash_Scripting.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
55
56
57
58
59
60
###############################
# Variables in Bash Scripting #
###############################
### Creating an array
# Create a normal array with the mentioned elements
capital_cities=("Sydney" "New York" "Paris")
# Create a normal array with the mentioned elements using the declare method
declare -a capital_cities
# Add (append) the elements
capital_cities+=("Sydney")
capital_cities+=("New York")
capital_cities+=("Paris")
# Print out the entire array
echo ${capital_cities[@]}
# Print out the array length
echo ${#capital_cities[@]}
### Creating associative arrays
# Create empty associative array
declare -A model_metrics
# Add the key-value pairs
model_metrics[model_accuracy]=98
model_metrics[model_name]="knn"
model_metrics[model_f1]=0.82
# Declare associative array with key-value pairs on one line
declare -A model_metrics=([model_accuracy]=98 [model_name]="knn" [model_f1]=0.82)
# Print out the entire array
echo ${model_metrics[@]}
# Print out just the keys
echo ${!model_metrics[@]}
############################
# Functions and Automation #
############################
### Creating cronjobs
# Create a schedule for 30 minutes past 2am every day
30 2 * * * bash script1.sh
# Create a schedule for every 15, 30 and 45 minutes past the hour
15,30,45 * * * * bash script2.sh
# Create a schedule for 11.30pm on Sunday evening, every week
30 23 * * 0 bash script3.sh