我的脚本需要获取 OU 父帐户, 请注意,我确实有一个有效的 bash 脚本,仅在分配给变量时才在 aws cli 命令上使用波形符引号,这是完全相同的,但对于 --parentid/--child-id 参数 因此不需要外壳检查
当我在终端上运行相应的 aws cli 时,它工作正常,我有
```
aws organizations list-parents --child-id <acctid input> --query Parents[*].Id --output text
```
但是,当我在 bash 中使用相同的值时,如下所示,它不会分配值,进程会清空。 bash 脚本有
```
for account in $(aws organizations list-accounts --query 'Accounts[].Id' --output text); do
echo $account
parent_ou=`aws organizations list-parents --child-id $account --query Parents[*].Id --output text`
echo $parent_ou
```
工作脚本中唯一添加的是parent_ou
的分配请注意,它确实正确打印帐户,因此只有parent_ou 分配不起作用。与另一个有类似的问题,该问题在终端上有效,但在 bash 中无效,请注意模拟的parent_id
```
b_ous = `aws organizations list-organization-units-for-parent --parent-id o_hhhhh_**** --query OrganizationalUnits[*].Id --output text`
```
错误是
```
command "o_hhhhh_****" not found
```
我尝试使用变量而不是硬编码值,它是同样的错误。
你知道 bash 中这些变量赋值可能有什么问题吗?
提前致谢
这对我有用
对于 $(aws Organizations list-accounts --query 'Accounts[].Id' --output text) 中的帐户;做 回显“$帐户” Parent_ou=$(aws Organizations list-parents --child-id "$account" --query Parent[*].Id --output text | tr -d ' ') 回声“$parent_ou” 完成
我必须像上面那样将parent_ou的cli命令放在$();中