将元素添加到现有数组 Bash

blu*_*ndr 5 arrays bash

我需要分几个步骤处理一些数据。

我首先在 AWS 中创建一个托管策略列表,并将该列表放入一个数组中:

readarray -t managed_policies < <(aws iam list-attached-user-policies --user-name tdunphy  --output json --profile=company-nonprod | jq -r '.AttachedPolicies[].PolicyArn')
Run Code Online (Sandbox Code Playgroud)

但随后我需要在我的脚本中向该数组添加更多信息。我的问题是,我可以使用 readarray 来做到这一点吗?或者我是否只需要使用以下命令将数据修改到列表中:

managed_policies+=($(aws iam list-attached-group-policies --group-name grp-cloudops --profile=compnay-nonprod | jq -r '.AttachedPolicies[].PolicyArn'))
Run Code Online (Sandbox Code Playgroud)

Cyr*_*rus 11

我建议使用选项-O附加到您的数组:

mapfile -t -O "${#managed_policies[@]}" managed_policies < <(aws ...)
Run Code Online (Sandbox Code Playgroud)