I have two arrays and I want to create them as a key/value pairs, i.e., build an associative array out of them.
This is my code:
#!/bin/bash
a=$(awk -F{ '{print $1}' test.txt) #output: [Sun Mon Tues Wed Thu Fri Sat]
b=$(awk -F "[{}]" '{print $2}' test.txt) #output: [03:00 05:00 07:00 03:00 05:00 07:00 07:00]
declare -A arr
for j in $b
do
time=$j
for k in $a; do
days=$k
arr["$days"]=$time
done
done
echo ${arr[@]} # o/p: 07:00 07:00 07:00 07:00 07:00 07:00 07:00
I'm getting this output:
"07:00 07:00 07:00 07:00 07:00 07:00 07:00"
but I'm expecting
03:00 05:00 07:00 03:00 05:00 07:00 07:00
How can I do that?
$band$aare strings. Did you mean"${b[@]}"and"${a[@]}"?for j in ... time=$j ...and not justfor time in ...?