1

Let's say I have the following code:

#!/bin/bash

arrayName_1=( 3 4 5 )
arrayName_2=( 0 1 2 )
str="arrayName_1"
arrayName=?

In the end, I want arrayName variable to be an array containing 3, 4, 5, just like arrayName_1. How do I make this happen? I know I could do the below, but I have to use str instead of arrayName_1:

arrayName=("${arrayName_1[@]}")

1 Answer 1

4

Try this:

arrayName_1=( 3 4 5 )
arrayName_2=( 0 1 2 )
name="arrayName_1"
indirect=$name"[@]"
arrayName=("${!indirect}")
Sign up to request clarification or add additional context in comments.

1 Comment

Awesome! Exactly what I wanted.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.