$ P $在bash阵列ppending所有项目的变量 [英] Prepending a variable to all items in a bash array
本文介绍了$ P $在bash阵列ppending所有项目的变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
CURRENTFILENAMES=( "$(ls $LOC -AFl | sed "1 d" | grep "[^/]$" | awk '{ print $9 }')" )
我已经写了上面的code,但我期待它在一个for循环,这是我写的,因此不表现
I have written the above code, however it is not behaving as I expect it to in a for-loop, which I wrote as so
for a in "$CURRENTFILENAMES"; do
CURRENTFILEPATHS=( "${LOC}/${a}" )
done
这我预计prePEND变量中的值 LOC
来都在 CURRENTFILENAMES
阵列,但它刚刚$ p $它ppended到数组的开头,我怎么能解决这个问题?
Which I expected to prepend the value in the variable LOC
to all of the items in the CURRENTFILENAMES
array, however it has just prepended it to the beginning of the array, how can I remedy this?
推荐答案
您需要使用 + =
运营商追加到一个数组:
You need to use +=
operator for appending into an array:
CURRENTFILEPATHS+=( "${LOC}/${a}" )
不过解析 LS
输出是不可取的,使用找到
代替。
However parsing ls
output is not advisable, use find
instead.
编辑:有道运行这个循环:
CURRENTFILEPATHS=()
while IFS= read -d '' -r f; do
CURRENTFILEPATHS+=( "$f" )
done < <(find "$LOC" -maxdepth 1 -type f -print0)
这篇关于$ P $在bash阵列ppending所有项目的变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文