-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.sh
More file actions
executable file
·147 lines (109 loc) · 2.86 KB
/
script.sh
File metadata and controls
executable file
·147 lines (109 loc) · 2.86 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#!/usr/bin/bash
# !/usr/bin/python3
echo "Hello, World"
# print("hello from python")
passing args to script
echo "Hello, $1!"
echo "Welcome!"
echo "Your age is: $2"
echo "Total args passed: $#"
echo "All args: $@"
# echo
# single, double-quotes, backticks shell within a shell
# echo 'Datetime: `date`'
# echo 'Datetime: $(date)'
# echo "Datetime: `date`"
# echo "Datetime: $(date)"
# echo
# shell-in-shell, continued
# date_time=$(echo $(date) | cut -d " " -f 2,3)
# echo "Todays date is: $date_time"
# numbers in shell
# expr 5 + 3
# echo $((5 + 3))
# echo "10/3" | bc
# echo "scale=2; 10/3" | bc
# declare -a first_array
# first_array+=(1 2 3 4)
# echo "First array: ${first_array[@]}"
# echo "First array: ${first_array[*]}"
# echo "Length of first array: ${#first_array[@]}"
# echo "First element: ${first_array[0]}"
# echo "slice: ${first_array[@]:1:2}"
# echo
# # create and add elements at the same time
# second_array=(5 6 7 8)
# echo "Second array: ${second_array[@]}"
# echo "Length of second array: ${#second_array[@]}"
# echo "First element: ${second_array[0]}"
# echo
# third_array=(5 7 10 21)
# echo "Third array: ${third_array[@]}"
# third_array[0]=33 # replacing element
# echo "Third array: ${third_array[@]}"
# third_array+=(61) # appending to array
# echo "Third array: ${third_array[@]}"
# echo "slice: ${third_array[@]:1:2}"
# echo
# associative arrays
# declare -A city_details
# city_details=([name]="Calgary" [population]=1600000 [province]="AB")
# echo ${city_details[@]}
# echo "Keys: ${!city_details[@]}" # return all keys
# echo
# declare -A city_details2=([name]="Vancouver" [population]=3000000 [province]="BC")
# all_cities=(city_details city_details2)
# for city_name in "${all_cities[@]}"; do
# declare -n city="$city_name"
# echo "City: ${city[name]}"
# echo "Population: ${city[population]}"
# echo "Province: ${city[province]}"
# echo "---"
# done
# if grep -q 'sydney' $1; then
# mv $1 sydney/
# fi
# if grep -q 'melbourne|brisbane' $1; then
# rm $1
# fi
# if grep -q 'canberra' $1; then
# mv $1 "IMPORTANT_$1"
# fi
# case $(cat $1) in
# *sydney*)
# mv $1 sydney/ ;;
# *melbourne*|*brisbane*)
# rm $1 ;;
# *canberra*)
# mv $1 "IMPORTANT_$1" ;;
# *)
# echo "No cities found" ;;
# esac
# case $(cat $1) in
# *sydney*)
# cp $1 sydney/ ;;
# *melbourne*|*brisbane*)
# rm $1 ;;
# *ring*)
# cp $1 "IMPORTANT_$1" ;;
# *)
# echo "No cities found" ;;
# esac
# function_name () {
# #some_code
# return #something
# }
# function function_name {
# #some_code
# return #something
# }
# function print_hello () {
# echo "Hello world!"
# }
# print_hello # calling the function
# function print_filename {
# local first_filename=$1
# echo "Inside: $first_filename"
# }
# print_filename "TwoTowers.txt" "LOTR.txt"
# echo "Outside: $first_filename"