有人可以告訴我為什么在附加到新陣列時將我的值分成兩個陣列元素嗎?
這是我的代碼,輸出如下...
#!/bin/bash
IFS=$'\r\n' GLOBIGNORE='*' command eval 'toexec=($(cat /root/devops/commands.txt))'
#printf '%s\n' "${toexec[@]}"
dirlist=(`ls /root/devops/files/*`)
toCompress=()
toOutput=()
for fileList in ${dirlist[*]}
do
toOutput =($(basename ${fileList}));
toCompress =("${fileList}"$'\n');
done
newOut=()
printf '%s\n' "${toexec[@]}"
for (( i=0; i<${#toexec[@]}; i ));
do
newval="${toexec[$i]},${toOutput[$i]}"$'\n';
newOut =($newval);
done
echo "======"
printf '%s\n' "${newOut[@]}"
這是輸出,由 ===== 分隔,現有陣列在頂部,新陣列在底部。如您所見,它將每個元素放入兩個元素中,在gzip
和之間的單個空格上拆分option,filename
,例如gzip
and -1,a.txt
。
輸出
gzip -1
gzip -9
======
gzip
-1,a.txt
gzip
-9,b.txt
...
==debug additional info==
--toexec < commands.txt--
gzip -1
gzip -9
=========================
--toCompress < ls--------
=========================
/root/devops/files/a.txt
/root/devops/files/b.txt
----toOutput-------------
a.txt
b.txt
=========================
----newOut---------------
gzip
-1,a.txt
gzip
-9,b.txt
=========================
uj5u.com熱心網友回復:
因為該值不是雙引號,如
newOut =("$newval")
這會將單個元素添加到陣列中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/475400.html
上一篇:根據JavaScript中的屬性值從物件陣列中洗掉重復項
下一篇:返回列表