Regard input string as defined array name in BASH -


i working on script receives input string , use defined array name. stuck this, in advance

a=(1 2 3) b=(4 5 6) c=(7 8 9) 

if input user "a", want result_array (1 2 3)?

a=(1 2 3); b=(4 5 6); input="a"; result_array=("${${input}[@]}"); echo ${result_array[@]}  bash: ${${input}[@]}: bad substitution 

all want is: result_array=("${${input}[@]}") => result_array=("${a[@]}") = (1 2 3)

note: dont want use if statements "if input = or b or c, result_array= or b or c", because have step many times.

a=(1 2 3);  b=(4 5 6); # ... input="a"; # user input result_array=${input}[@]; echo \(${!result_array}\) 

will print:

(1 2 3) 

Comments

Popular posts from this blog

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

python Tkinter Capturing keyboard events save as one single string -

sql server - Why does Linq-to-SQL add unnecessary COUNT()? -