Isn’t this basically the same problem as the need to update the DISPLAY variable when X11 forwarding is enabled?
Why not a more general approach like this?
https://www.johntobin.ie/blog/updating_environment_variables...
Why not a more general approach like this?
https://www.johntobin.ie/blog/updating_environment_variables...