myvbox-stop-all: added support for spaces in the response from "vboxmanage list runningvms".
authorOleksandr Gavenko <gavenkoa@gmail.com>
Wed, 08 Jun 2022 00:39:34 +0300
changeset 998 1b3bc0a2de41
parent 997 02ca7e4cc631
child 999 fb93b077af25
myvbox-stop-all: added support for spaces in the response from "vboxmanage list runningvms".
.bashrc
--- a/.bashrc	Tue Jun 07 13:41:05 2022 +0300
+++ b/.bashrc	Wed Jun 08 00:39:34 2022 +0300
@@ -329,8 +329,11 @@
         total:  %{time_total}\n" "$@"
 }
 
-myvbox-halt-all() {
-  vboxmanage list runningvms |& tr -d '\r' | while read name uuid; do
-    vboxmanage controlvm "$uuid" acpipowerbutton
+myvbox-stop-all() {
+  VBoxManage list runningvms |& while read line; do
+    # Parse UUID in: "Name with spaces" {UUID}
+    line=${line##*'{'}
+    line=${line%'}'*}
+    VBoxManage controlvm "$uuid" acpipowerbutton
   done
 }