forked from rbawah/bash_data
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.sh
More file actions
113 lines (82 loc) · 2.2 KB
/
script.sh
File metadata and controls
113 lines (82 loc) · 2.2 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
#!/usr/bin/bash
# declare -a first_array
# first_array+=(1 2 3 4)
# echo "First array: ${first_array[@]}"
# echo "Length of first array: ${#first_array[@]}"
# echo "First element: ${first_array[0]}"
# 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}"
# 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")
# echo ${city_details2[@]}
# 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"