BMardle
Posts: 107
Joined: Wed Feb 13, 2013 4:00 pm
Location: Isle of Wight

Environment variables vs. bash and lxterminal

Wed Apr 17, 2019 12:37 pm

Hi, all.
I recently tried to run 1 of my 'old' OpenGL/ES programs on my Pi 2 (Stretch). It didn't work because LD_LIBRARY_PATH wasn't set.
I've put "export LD_LIBRARY_PATH=/vc/opt/lib" (or something similar!) in ~/.bash_profile. When I first log in (using the text console, not X), LD_LIBRARY_PATH is set. If I then run `startx` then click on the icon to start lxterminal, LD_LIBRARY_PATH isn't set.
(Weirdly, I did `ls -lut ~/.bash*` and none of them seemed to have been accessed recently!)
Any idea how to keep LD_LIBRARY_PATH set?
(I added an echo to ~/.bash_profile, and, sure enough, it's run when I initially log in but not when starting lxterminal.)
Bruce Mardle. "You know I yearn for a simpler time of barn dances and buggy rides before life was cheapened by heartless machines."

User avatar
jojopi
Posts: 3064
Joined: Tue Oct 11, 2011 8:38 pm

Re: Environment variables vs. bash and lxterminal

Wed Apr 17, 2019 1:57 pm

BMardle wrote:
Wed Apr 17, 2019 12:37 pm
(Weirdly, I did `ls -lut ~/.bash*` and none of them seemed to have been accessed recently!)
You cannot rely on access times. Many distros and images mount filesystems with the "noatime" or "relatime" options by default. Especially on an SD card, where small writes are costly, frequent access time updates could impact performance in many workloads.
(I added an echo to ~/.bash_profile, and, sure enough, it's run when I initially log in but not when starting lxterminal.)
That is correct behaviour. Profiles are sourced only in login shells, and lxterminal is not a login shell (unless started with the --loginshell option).

Assuming that you are using Raspbian:
  • Delete .bash_profile. It is not supposed to exist.
  • Bash will fall back to using plain .profile. Check that this does still exist, or copy it from /etc/skel/ if not.
  • Put your export command in .bashrc so that it works in non-login shells.
  • In a login shell, your .profile will automatically source .bashrc, so it works there too.
It may also work to put the export only in .profile, since the X session considers itself a login. However, for something like export that is safe to execute multiple times, you might as well do it in every shell.

BMardle
Posts: 107
Joined: Wed Feb 13, 2013 4:00 pm
Location: Isle of Wight

Re: Environment variables vs. bash and lxterminal

Wed Apr 17, 2019 2:12 pm

jojopi wrote:
Wed Apr 17, 2019 1:57 pm
You cannot rely on access times. Many distros and images mount filesystems with the "noatime" or "relatime" options by default. Especially on an SD card, where small writes are costly, frequent access time updates could impact performance in many workloads.
Thanks, jojopi. I thought it might be something like that, but when I ran `mount`, the output was so copious that I fled, screaming :)
That is correct behaviour. Profiles are sourced only in login shells, and lxterminal is not a login shell (unless started with the --loginshell option).
Ah! I assumed that the lxterminal's bash would inherit its parent's environment (or it's grandparent's environment or...).
I'll give your suggestions a go.
Bruce Mardle. "You know I yearn for a simpler time of barn dances and buggy rides before life was cheapened by heartless machines."

Return to “Troubleshooting”