Quote:
Originally posted by janisj
[B]Question(s): how to get the same environment variables into a Terminal that I open from GNOME graphical environment?
|
In order to get the X Terminal emulator shell to have the same environment variables, it must also source $HOME/.profile. The way to get it to source
$HOME/.profile is to make it a login shell with the appropriate command
line flags when it is invoked. If the terminal is being invoked from a menu,
then you have to edit the menu to add the command line flags.
Does that make sense?
Now if you have followed that, there is a trick we can play using the ENV
variable.
If you always want your $HOME/.kshrc to be sourced regardless of whether or not the shell be it in an X Terminal Emulator or not is login shell, then it can be done.
When the user logs in under the Graphical Display manager that is
a login shell by definition so /etc/profile and $HOME/.profile will
be read. Presumably because you are not EXPORTing all your
variables in your $HOME/.profile, these variable will not be seen
in children of the parent login process. Why you are not EXPORTing
these variables, I do not know, since if they were, then this whole
problem should not have arisen.
But regardless of that, if you put an entry in your $HOME/.profile
ENV=$HOME/.kshrc
export ENV
then the ENV variable will be seen in all child processes.
Going back to what I previously posted from the ksh man page
If the ENV parameter is set when the shell starts (or, in the case of login shells, after any profiles are processed), its value is subjected to parameter, command, arithmetic and tilde substitution and the resulting file (if any) is read and executed.
regardless of it being a login shell or not, the new shell will read
and execute the file pointed to by ENV.
Hence if you put your interactive non-login shell variables in your .kshrc they will be set, provided ENV is set and exported from $HOME/.profile.
BE careful never to put any terminal specific commands in your .kshrc
since this file will be executed regardless of whether the process is
attached to a terminal (eg process invocation by rsh or ssh.)
And if you do need to do then always do a test
tty -s
status=${?}
if [ ${status} -eq 0 ]
then
<tab> do tty specific commands here
fi
Quote:
As a secondary question -- who eats the environment variables between login and opening of the Terminal; why are the environments different?
|
NOBODY EATS VARIABLES FOR BREAKFAST! :+)
Nobody prefers Cheerios (or subsitute favorite breakfast cereal here).
Here's how it works -- Unix is a land of processes.
There is a parent process in which variables are set, in the case of a ksh login in /etc/profile.
The parent spawns a new process. In fact it spawns lots and lots.
Every time you fire up an X terminal emulator, new processes
are started -- the X Terminal emulator itself and the shell contained
within it!
Child processes inherit the environment of their parents EXCEPT
that shell variables are only inherited if their parents EXPORT the
shell variable.
Here is a quick test.
Type
$ variable1="oranges"
$ export variable1
$ ksh
You are now in a new ksh within the parent ksh
now type
$ echo $variable1
You will see the value "oranges"
now type
$ variable2="apples"
$ ksh
You are now in a new ksh within the child ksh of the original ksh
$ echo $variabl1
oranges
$ echo $variable2
$
You see nothing. the variable does not exist. It was not exported.
Now before you forget where you are
$ exit
leaves the child of child shell
$ exit
leaves the child and back to the very original shell.
So does this illustrate why some variables are disappearing?
Quote:
I hope the question is understandable.
|
You expressed the question in clear and concise terms,
which is what was required. I just hope my explanation was clear enough
for you. For further help consult man ksh, or may I mention the O'Reilly
book "Learning the Korn Shell".
Quote:
Please do not tell me -- ". ~/.profile" in the Terminal.
|
Only lazy, unthinking, unimaginative types come back with answers like that. The whole point of software is to make life easier not give you more work to do. There is nearly always a way to get such things to work, but you have to do some work to get them to work :+)
Oh and by the way I hate ksh; bash is okay, but I am a diehard tcsh person!
And to quote a friend of mine
"We are all children of init."
Do a ps -adef | less on any Unix SysV system (or ps -auwx | less on any
Unix BSD system) and you will see that the very first process with pid 1 is init. Every other process is a child of that.