Is there in bash scripts a way of using variables to specify different bash arrays
by stewate4 from LinuxQuestions.org on (#5MXKZ)
For example in this simple script
#!/bin/bash
declare -a MYARRAY1
declare -a MYARRAY2
function updatearray {
ARRAY=$1
VALUE=$2
$ARRAY+=$VALUE
}
updatearray MYARRAY1 "yyyy "
updatearray MYARRAY2 "bbbb "
echo "${MYARRAY1[@]}"
echo "${MYARRAY2[@]}"
exit 0
Just results in "line 10: MYARRAY1+=yyyy: command not found" rather than updating the array. This is actually for a more complex bash script I'm working on that has more arrays I want to update, so I'm hoping to avoid 'case' statements which would mean a big function body
#!/bin/bash
declare -a MYARRAY1
declare -a MYARRAY2
function updatearray {
ARRAY=$1
VALUE=$2
$ARRAY+=$VALUE
}
updatearray MYARRAY1 "yyyy "
updatearray MYARRAY2 "bbbb "
echo "${MYARRAY1[@]}"
echo "${MYARRAY2[@]}"
exit 0
Just results in "line 10: MYARRAY1+=yyyy: command not found" rather than updating the array. This is actually for a more complex bash script I'm working on that has more arrays I want to update, so I'm hoping to avoid 'case' statements which would mean a big function body