[英]Multiple arrays loop shell
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 但是当我运行它时,不要替换$ FILENAME
On Google I can't find much about arrays and variables, anyone could please help me? 在Google上,我找不到关于数组和变量的内容,有谁可以帮助我? ;) Thanks!
;) 谢谢! Alex
亚历克斯
bash --version GNU bash, version 3.1.17(1)-release bash --version GNU bash,版本3.1.17(1) - 发布
Try using +=
to append elements to trigarrat
: 尝试使用
+=
将元素附加到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 参考: http : //www.gnu.org/software/bash/manual/bashref.html#Shell-Parameters
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.