I'm on Ubuntu focal and trying to start
VBoxManage list vms
using a different config directory. This can be achived by changing (or setting)
VBOX_USER_HOME and works quite well in terminal if simply I type:
export VBOX_USER_HOME="/new/config/path" VBoxManage list vms
However when I try the same code from a bash script :
#!/bin/bash export VBOX_USER_HOME="/new/config/path" echo "$VBOX_USER_HOME" env | grep VBOX_USER_HOME VBoxManage list vms
the variable is not "seen" by
VBoxManage so that it lists the VMs configured at the default location even though the variable was apparently successfully exported to env. Here is how the output looks like:
/new/config/path VBOX_USER_HOME=/new/config/path lists the machines from default config
I know that
/usr/bin/vboxmanage is a link to a script which calls eventually the real application
$INSTALL_DIR/VBoxManage. Just to make sure the VBox scripts do not clean the environment I tried calling the binary directly. However, this made no difference.
So, how comes the exported variable is visible to
$INSTALL_DIR/VBoxManage when I do the export from the terminal but is invisible when I do it from a script?
I just found out that this is some kind of race condition issue with Virtual Box. If I do the export in the terminal and directly run
$INSTALL_DIR/VBoxManage list vms afterwards, it erroneously shows the VMs from the default config just like the script.
Subsequent calls then always return the old list Subsequent calls show after 5 to 10 seconds the new list. If I do the export and wait a little longer, the list is correctly updated to the VMs configured at the new location. Subsequent calls now always return the new list. So the solution to my problem is to insert a sleep into the script. Anyway, I will reward answers that can explain this unexpected behaviour.