[GRASS-dev] Wrong HOME environment variable at start-up

Glynn Clements glynn at gclements.plus.com
Mon Mar 2 20:25:48 PST 2015


Nikos Alexandris wrote:

> In ~/.grass.bashrc, I put the test-line `echo ~  # or echo $HOME`  
> (sans backticks, of course).
> Launching up G70, or G71, the echoed message reports HOME as being the 
> Mapset in which I launch GRASS!  For example, `grass70 
> /geo/grassdb/ols/PERMANENT` will give "/geo/grassdb/ols/PERMANENT".
> 
> Thus, `source ~/.bash_aliases`, inside .grass.bashrc, fails to deliver. 
> Now, asking for $HOME, inside GRASS, shows no error, ie: `echo $HOME` 
> gives "/home/nik".  Nevertheless, there is no single line anywhere in  
> ~/.bash*  or  ~/.grass*  or  ~/.grass7/*  that refers to HOME.
> 
> Can someone help me understand what I have probably setup wrong?

Before starting the child shell process, the startup script sets HOME
to the mapset directory and writes out a .bashrc file to that
directory which (among other things) sets HOME back to the correct
value. The contents of ~/.grass.bashrc are copied into that file, but
before the point that HOME is reverted.

This is essentially a hack to force the shell's history file to be
written to the mapset directory rather than the user's HOME directory,
so that each mapset has its own separate shell history.

For bash, it would probably be better to just set HISTFILE, but other
shells may not have such a feature.

For all shells, it may be better to restore HOME before executing the
user-supplied commands from ~/.grass.bashrc, ~/.grass.cshrc, etc.

In the meantime, you could have ~/.grass.bashrc restore HOME itself;
nothing written to the generated .bashrc file uses it.

-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-dev mailing list