【发布时间】:2021-09-03 12:52:34
【问题描述】:
我有一些遵循以下模式的工作代码。
FIRST_BILLING_ACCOUNT=$(gcloud beta billing accounts list --filter=open=true --format="value(name)" --limit=1)
检查输出:$FIRST_BILLING_ACCOUNT
打印我的结算帐户名称。
像这样:
REGION=$(gcloud app describe --format="value(locationId.scope())")
检查输出:$REGION
打印区域。
问题
这不起作用:
OUT=$(gcloud builds list --ongoing)
它打印输出:Listed 0 items. 并且不将值保存在 $OUT 中。
其他不起作用的东西,从这里拉出来:How do I redirect output to a variable in shell?
OUT="$(gcloud builds list --ongoing)"
gcloud builds list --ongoing | read OUT
read OUT < <(gcloud builds list --ongoing)
我什至试过这个:
echo "gcloud builds list --ongoing" >> tst.sh
chmod +x tst.sh
OUT=$(./tst.sh)
$OUT
结果是一样的。
我想知道两件事:如何捕获此命令的输出? 为什么不同的 gcloud 命令的行为似乎不同?
【问题讨论】: