Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • 3
    I'm surprised this works for you in bash on Ubuntu 18.04, AFAIK even there the arrays need to be declared with -A (associative) rather than -a (indexed) as per jesse_b's answer Commented Jun 25, 2021 at 19:58
  • @steeldriver: That is correct however depending on the variable contents it may not error, evaluate the object inside the index as 0, and overwrite the first element. Commented Jun 25, 2021 at 20:01
  • 1
    Suggestion for replacement of that while loop: eval "$( jq -r '.[] | (.name|@sh) as $n | (.hash|@sh) as $h | "_name[\($n)]=\($n)", "_hash[\($n)]=\($h)"' <<<"$BACKUP_REPOS" )". In any case -c is not needed with jq there. Commented Jun 25, 2021 at 22:18
  • Why three quotes at the start and end of the variable assignment? Commented Jun 26, 2021 at 7:49