Try maybe adding the export command to $HOME/.bashrc.
That also worked from terminal but not from ES.
So what I think is happening is this: autostart.sh is called from /etc/profile.d/10-retropie.sh which runs as part of /etc/profile. Then once that's complete it calls .profile and .bashrc.
But since the environment var is set in autostart it is perhaps disconnected from the profile service and so maybe the variable is local only to that shell. So it works from inside ES but when I exit ES and the autostart shell terminates, the var goes away and it doesn't work from terminal.
When I set it in .profile or in .bashrc it works from terminal, but these aren't processed until after ES exits because that's part of autostart which happens while /etc/profile is still going on.