Shell脚本-从返回的块中获取指定值
我希望使用shell获取返回的Shell脚本-从返回的块中获取指定值,shell,sh,Shell,Sh,我希望使用shell获取返回的状态值,然后我可以处理下一个命令 # glance image-show 0227a985-cb1e-4f0c-81cb-003411988ea5 +---------------------+--------------------------------------+ | Property | Value | +---------------------+------------
状态值
,然后我可以处理下一个命令
# glance image-show 0227a985-cb1e-4f0c-81cb-003411988ea5
+---------------------+--------------------------------------+
| Property | Value |
+---------------------+--------------------------------------+
| checksum | None |
| container_format | bare |
| created_at | 2021-03-15T02:54:15Z |
| disk_format | raw |
| hw_disk_bus | scsi |
| hw_qemu_guest_agent | yes |
| hw_scsi_model | virtio-scsi |
| id | 0227a985-cb1e-4f0c-81cb-003411988ea5 |
| locations | [] |
| min_disk | 0 |
| min_ram | 0 |
| name | not_inuse |
| os_hash_algo | None |
| os_hash_value | None |
| os_hidden | False |
| os_require_quiesce | yes |
| owner | 4d97a99e53bd4b51aa58601985776d5c |
| protected | False |
| size | None |
| status | active |
| tags | [] |
| updated_at | 2021-03-15T02:54:30Z |
| virtual_size | Not available |
| visibility | private |
+---------------------+--------------------------------------+
如何获取打印值=活动
# glance image-show 0227a985-cb1e-4f0c-81cb-003411988ea5 | grep status
| status | active |
请帮助,谢谢你
awk'/status/{print$4}'
,你不需要grep
@CharlesDuffy:也许最好awk'$2==“status”{print$4}'
,这样名字行也会包含status这个词作为值。@user1934428。。。如果名称的值被保证为十六进制格式的uuid,那么这不应该是一个风险,但一般来说肯定是更好的做法。@CharlesDuffy:正确,但是name
的当前值不是uuid,而是在使用中的值,而hw\u scsi\u model
的值也不是uuid。事实上,我不知道这张桌子是从哪里来的,所以我想还是安全为好。
# glance image-show 0227a985-cb1e-4f0c-81cb-003411988ea5 | grep status | awk '{print $4}'
active