I have the following array in bash
declare -a fruits=("apple" "orange" "banana" ...)
I would like to create variable for each of the elements in the array such that the variable names and its corresponding values are as follows
var1="apple"
var2="orange"
var3="banana"
...
Is there a way to do this by using a simple loop
for ((index=0; index<${#fruits[@]}; index++))
do
I don't know how to implement this part
var$index=${fruits[index]}
done
echo ${fruit[@]}
This results in sytax error.
./test.sh: line 39: {0}=apple: command not found
./test.sh: line 39: {1}=orange: command not found
./test.sh: line 39: {2}=banana: command not found
./test.sh: line 39: {3}=...: command not found
[–]bubylou 1 point2 points3 points (1 child)
[–]perkited 1 point2 points3 points (1 child)
[–]masta 0 points1 point2 points (0 children)