Reputation: 2127
I have a problem building a "dynamic" array.
First of all I create an array to generate a list of names of files:
declare -a pgidarr=`run "select partition_id from ETL.PARTITION_GROUP_MEMBER where partition_group_id=${PGID}"`
for i in ${pgidarr[@]}
do
ARRLOOP=$i
PAID=`run "select LPAD('${ARRLOOP}',2,'0')"` #LPAD the partition ID
FILENAME=ABCD_${PAID}_000000.txt
Now in the same loop I want to create a NEW array
trigarrat=("${trigarrat[@]}" $FILENAME)
But when I run it doens't replace $FILENAME
On Google I can't find much about arrays and variables, anyone could please help me? ;) Thanks! Alex
bash --version GNU bash, version 3.1.17(1)-release
Upvotes: 1
Views: 104
Reputation: 3958
Try using +=
to append elements to trigarrat
:
declare -a pgidarr=`run "select partition_id from ETL.PARTITION_GROUP_MEMBER where partition_group_id=${PGID}"`
trigarrat=()
for i in ${pgidarr[@]}
do
ARRLOOP=$i
PAID=`run "select LPAD('${ARRLOOP}',2,'0')"` #LPAD the partition ID
FILENAME=ABCD_${PAID}_000000.txt
trigarrat+=($FILENAME)
done
Reference: http://www.gnu.org/software/bash/manual/bashref.html#Shell-Parameters
Upvotes: 3