-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy patharray.sh
executable file
·47 lines (37 loc) · 863 Bytes
/
array.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
#!/bin/bash
#################################
# Populando e utilizando Arrays #
#################################
array_par=()
array_impar=()
function popula_array(){
while read LINE
do
if [ "$(($LINE % 2))" -eq 0 ]; then
array_par=("${array_par[@]}" "$LINE")
else
array_impar=("${array_impar[@]}" "$LINE")
fi
done < popula_array.txt
}
function print_array_par(){
echo -e "\n######### Array #########\n"
for i in ${array_par[@]}
do
echo -e "Valor: $i"
done
# Mostra o Total de elementos
echo -e "\nTotal de Elementos Pares: ${#array_par[@]}"
}
function print_array_impar(){
echo -e "\n######### Array #########\n"
for i in ${array_impar[@]}
do
echo -e "Valor: $i"
done
# Mostra o Total de elementos
echo -e "\nTotal de Elementos Impares: ${#array_impar[@]}"
}
popula_array
print_array_par
print_array_impar