输出格式与结果过滤
更新时间:2026-06-10
输出格式
通过 --output 指定输出格式,默认为 json。
JSON(默认)
Bash
1bce vpc QueryVpcList
带颜色高亮(连接终端时自动启用),可用 --no-color 关闭。
Table
Bash
1bce vpc QueryVpcList --output table
自动以响应中的数组字段为行、字段名为列生成表格。
指定列:
Bash
1bce vpc QueryVpcList --output "table cols=vpcId,name,cidr"
指定行数据来源(JMESPath 提取数组):
Bash
1bce vpc QueryVpcList --output "table rows=vpcs cols=vpcId,name,cidr"
Text
输出单个值,适合脚本赋值:
Bash
1bce vpc QueryVpcList --query "vpcs[0].vpcId" --output text
JMESPath 结果过滤
--query 对响应结果进行精确提取,语法遵循 JMESPath 规范。
提取单个字段:
Bash
1bce vpc QueryVpcList --query "vpcs[0].vpcId"
提取数组中所有名称:
Bash
1bce vpc QueryVpcList --query "vpcs[].name"
条件过滤:
Bash
1bce vpc QueryVpcList --query "vpcs[?isDefault==\`true\`].vpcId"
与 table 组合:
Bash
1bce vpc QueryVpcList \
2 --query "vpcs" \
3 --output "table cols=vpcId,name,cidr"
评价此篇文章
