I want to loop through my running VM's and return only what is between quotes.
So this command:
VBoxManage list runningvms
returns:
"UbuntuServer" {7ef01f8d-a7d5-4405-af42-94d85f999dff}
And I only want it to return:
UbuntuServer
This is what i have so far (fail):
#!/bin/bash
for machine in `cat VBoxManage list runningvms`; do
echo "$machine"
done
exit
Warning: all of this is is risky if your VM names have shell glob characters in them, or contain spaces.
You can do something like this if there is only one running VM:
read machine stuff <<< $(VBoxManage list runningvms)
echo "$machine"
Alternative with bash arrays (same condition):
vbm=($(VBoxManage list runningvms))
echo "${vbm[0]}"
If that program returns more than one line, a more classic approach would be:
for machine in $(VBoxManage list runningvms|cut -d" " -f 1); do
echo "$machine"
done