I’m posting this at the prompting of another QNX user (It’s qrm’s fault)
I’ve had the most terrible time trying to understand where to put
environment variables such that when I run a pterm they show up. Especially
the PS1 variable.
Seems there are a few others that don’t understand either. Well…if this
is you, this is your lucky day.
First some basics:
-
When you login, the following occurs (there may be more stuff, but this
should be sufficient for this discussion.)
a. The $HOME variable is set from your home dir entry in the passwd
file (make sure this directory actually exists and that it is owned by you
and at least one of the groups to which you belong).
b. /etc/profile is run. This is a script MAKE SURE it has execute
permissions.
c. $HOME/.profile script is run…make sure this also has execute
permissions (these two have been problems for me and others)
d. A shell is started.
e. Before the shell gives you a prompt, it looks for the environment
var ‘ENV’, if set with a proper file name, will try to execute the file as a
script. -
One thing occurs when /etc/profile is run that is interesting. There is
a bit of code in there that attempts to set the $ENV variable.
This is set if the name used to start your shell (with a ‘.’ in front)
exists as a script (with execute permissions) in your home directory. So,
if you use ksh and it was started using sh, and you are ‘root’, and you have
created a /root/.sh file (with execute permissions) ENV will be set to
‘/root/.sh’. Thus when a shell is invoked, that script will be run.
This is important because there are some environment variables that get
overridden when the shell starts (i.e. PS1), so in order to get these, you
need to have a ‘.sh’ file that will set it for you. It isn’t good enough
for them to be in the $HOME/.profile script.
Now, what does this have to do with pterm?
Well…funny you should ask.
If you use the graphical login, it will run /etc/profile and
$HOME/.profile…you just won’t see it. Therefore it is important that if
you want to set a environment variable like ‘PS1’, you will need to create a
…sh file (or .bash if you are using bash (I think, I don’t use bash, so I
can’t say)) in your home directory and give it execute permissions. Put the
required ‘export PS1=blah blah blah’ in .sh.
Then when you start a pterm, the ‘.sh’ file will be executed and any
shifting environment variables can be set.
Note that there are many environment variables that will be inherited by the
shell from the execution of /etc/profile and $HOME/.profile (when you logged
into photon), so you don’t need to load ‘.sh’ with redundant stuff…
Hope this was useful. (no complaining about the bad grammar, I was in a
hurry!),
Kevin