Quantcast
Channel: Recent Questions - Stack Overflow
Viewing all articles
Browse latest Browse all 22544

How to copy Associative Array without for loop

$
0
0

I am looking for an efficient way to copy associative array because I am performing this action inside two nested for-loops in my main script.

Here's the general format which I am using in my main script:

#!/bin/bashdeclare -A oldLinksoldLinks["A"]="linkA"oldLinks["B"]="linkB"oldLinks["C"]="linkC"oldLinks["D"]="linkD"
#!/bin/bashsource exportThis.shdeclare -A copyLinksfor i in "${!oldLinks[@]}"; do  copyLinks[$i]=${oldLinks[$i]}donefor k in "${!copyLinks[@]}"; do  echo "$k -- ${copyLinks[$k]}"done

When I do it this way in my main script, I am getting this error:

bash: copyLinks: "${oldLinks[@]}": must use subscript when assigning associative array
copyLinks=("${oldLinks[@]}")

Viewing all articles
Browse latest Browse all 22544

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>