简体   繁体   English

bash:向数组添加元素

[英]bash: adding elements to array

in this code i just save paths into array#1. 在这段代码中,我只是将路径保存到array#1中。 This array works fine: 这个数组工作正常:

echo "Searching for *omd*-paths..."
cd /

# creating array#1
all_omd_paths=`find -type d -name omd`

Ok, but now i want to put specific paths into another array (array#2): 好的,但是现在我想将特定路径放入另一个数组(array#2):

for path in $all_omd_paths
do
        if [[ $path == *"s"* ]]; then
            # fill array#2
            omd_sites_paths+=($path)
        fi
done

for path in $omd_sites_paths
do
    # wrong output
    echo $path
done

With the second for-loop i just get ONE path on output... But i know there are more saved in array#1. 在第二个for循环中,我仅在输出中获得一个路径...但是我知道在array#1中还有更多保存。 What s wrong with array#2? 数组2有什么问题? How do i fill it correctly? 如何正确填充?

如果$ omd_sites_paths是一个数组:

for path in ${omd_sites_paths[@]}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM