您可以使用jq命令来转换输出格式。例如,以下脚本将查询名为“myvm”的虚拟机的IP地址,将输出格式转换为JSON,并使用jq命令来提取所需的IP地址:
#!/bin/bash
# Query the IP address of myvm virtual machine
query_result=$(az vm show -d -g myrg -n myvm --query publicIps -o json)
# Parse the JSON output to get the IP address
ip_address=$(echo $query_result | jq -r '.[0]')
echo "The IP address of myvm virtual machine is $ip_address"
您需要安装jq命令才能使用此脚本。要安装jq命令,请使用以下命令:
sudo apt-get install jq
运行脚本后,输出将为:
The IP address of myvm virtual machine is xxx.xxx.xxx.xxx
其中“xxx.xxx.xxx.xxx”是查询到的IP地址。