bash - 使用 VBoxManage 获取正在运行的虚拟机列表

标签 bash virtualbox

我想遍历正在运行的虚拟机并只返回引号之间的内容。

所以这个命令:

VBoxManage list runningvms

返回:

"UbuntuServer" {7ef01f8d-a7d5-4405-af42-94d85f999dff}

我只希望它返回:

UbuntuServer

这是我目前所拥有的(失败):

#!/bin/bash
for machine in `cat VBoxManage list runningvms`; do
        echo "$machine"
done
exit

最佳答案

VBoxManage list runningvms | cut -d '"' -f 2 | while read machine; do
   echo "$machine"
done

关于bash - 使用 VBoxManage 获取正在运行的虚拟机列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7069482/

相关文章:

bash - 这个 bash 东西的可搜索术语是什么 : <(command)

bash - 搜索和追加

ruby-on-rails - 将环境变量加载到 .railsrc 文件中?

linux - Hydra http 连接失败

windows - Makefile 错误 make (e=2) : The system cannot find the file specified

linux-kernel - virtualbox上的内核开发

ubuntu - 更新ubuntu内核的问题

python - 如何在ubuntu中为终端设置代理?

docker - 我可以使用已经存在的 VM 作为 docker-machine 吗?

ubuntu - Ubuntu上的VBox最大化问题