The problem is that for some variables the payload results are empty. In Node-RED with the inject node i have set the
$TEST -> result empty
$JOURNAL_STREAM -> result not empty
$USER -> result not empty
$GDMSESSION -> result empty
Can someone explain how node-RED handles the system $ environmental variables?
Yes, Node-RED is running locally the bash script and Node-RED installation is running in the same session/user. But it is not only the custom exported environment variabel that has a empty payload result but also for example the by default set "$GDMSESSION " variable is empty
So node red is not running the same session where you are checking the environment. It is running in a systemd session. Those environment variables are probably not set in that environment. For example GDMSESSION will not be set because node-red does not have a display attached. Similarly .bashrc is probably not run for that session.
You can set environment variables in the systemd script if that is appropriate for your needs.
so yes Node-RED is already running so it's environment has been set when it started. Any variables set after starting won't be updated. If you do a node-red-stop to stop that - then set your variable then just node-red (not node-red-start) - so it's started in the local environment it should then report correctly.
If you need to be able to specify environment variables for Node-RED, you can easily do so by tweaking the systemd service file. You will find examples in alternate-node-red-installer which I am, in fact, just updating.
You can provide an environment file as well which will be easier to amend if you need to make occasional changes. Of course, you still have to restart Node-RED each time you change them.
You can also change Node-RED's environment variables by setting them using node.js at the top of the settings.js file.
I've just pushed some changes to GitHub so do have a look at the version there. The whole repo is a bit rough and ready but it at least points the way.