加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

数组 – 从一个数组到另一个数组的Bash复制

发布时间:2020-12-15 19:06:58 所属栏目:安全 来源:网络整理
导读:我有一系列的应用程序。叫它, depends=(cat ~/Depends.txt) 当我尝试解析列表并将其复制到一个新的数组时, for i in "${depends[@]}" if [ $i #isn't installed ]; then newDepends+=("$i") fidone 会发生什么事情,只有依赖的第一个元素会依赖于新的数据
我有一系列的应用程序。叫它,
depends=(cat ~/Depends.txt)

当我尝试解析列表并将其复制到一个新的数组时,

for i in "${depends[@]}"
   if [ $i #isn't installed ]; then
      newDepends+=("$i")
   fi
done

会发生什么事情,只有依赖的第一个元素会依赖于新的数据。

for i in "${newDepends[@]}"
   echo $i
done

^^这只会输出一件事。所以我试图找出为什么我的for循环只是移动第一个元素。整个列表最初是依赖的,所以不是这样,但我都是出于想法。

a=(foo bar "foo 1" "bar two")  #create an array
b=("${a[@]}")                  #copy the array in another one 

for value in "${b[@]}" ; do    #print the new array 
echo "$value" 
done

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读