Background: I SSH into my Linux machine via Putty on my Windows machine. I am running VcXsrv on Windows and forwarding X over SSH. This is all working as expected.
I am running into issues opening gnome-terminal on the new display when executing the commands through a bash script.
When I execute these commands directly on the console, the new terminal server starts and I am able to start gnome terminal sessions that connect to the server.
$ /usr/libexec/gnome-terminal-server --app-id my.foo &  29553 $ gnome-terminal --app-id my.foo $
However, when I place the same commands into a shell script, I get the following error:
contents of startGnomeTerm.sh
#!/bin/bash /usr/libexec/gnome-terminal-server --app-id my.foo & gnome-terminal --app-id my.foo
When executing the script
$ ./startGnomeTerm.sh # Error creating terminal: The name my.foo was not provided by any .service files
I have even attempted to share all shell variables with the script by executing
$ export > shell_vars
Then placing this at the beginning of the script.
#!/bin/bash source shell_vars ....
The solution is to add a slight delay to between the commands. Setting up the server takes longer than the script was allowing for, so the terminal tried to connect before the server was actually running.
#!/bin/bash /usr/libexec/gnome-terminal-server --app-id my.foo & sleep 0.5 gnome-terminal --app-id my.foo