For suppose there is a code
comp="LP"
n_names="abc456.com,def123.com,wxy098.com"
IFS=',' read -r -a n_split_list <<< "$n_names"
Now I want to export the n_split_list array with the following variable format. Remember comp need not always be "LP" . It changes based on argument given to the script.
export "$comp"_list="${n_split_list[@]}"
but the problem is coming while exporting ( only first item of the array is getting exported ) Please help!
"$comp"_list=How would you use the variable later?? You can't doecho "${${comp}_list[@]}"- that's invalid. What is the point?Remember comp need not always be "LP"sure, but why would you want to create a variable with the name of other variable? What are the array and comp meant to represent? How are they meant to be used?var="${comp}_list[@]"; printf '%s\n' "${!var}".@works, your command is equivalent toexport "$comp"_list="${n_split_list[0]}" "${n_split_list[1]}" "${n_split_list[2]}".*, which would makeLP_listan ordinary space-delimited list of domain names, but that would defeat the purpose of using an array in the first place (and as dan points out, you cannot export an array itself).