Is it recommended to edit the file "/etc/environment" directly using vi ?
(like by adding some export something= value staements)
or
do we need to edit /etc/profile file
in order to set the environment variables, globally to the entire AIX LPAR
Either will work. By convention /etc/enviroment is used for environment variable defintions. So that's all you will usually see in it. Whereaas /etc/profile will also contain environmental vars but may contain additional commands. Compare yours to see.
yeah agreed. But i read somewhere, that we should not modify the /etc/environment file directly using vi.
i do not know....whether any command to update this file.
instead i usually edit (vi) /etc/profile and export the variables to make it global.
It is highly recommended to use vi for editing both of these files.
Still, putting "export"-statements into /etc/environment will not work at all and just lead to ignored lines causing error messages. In /etc/environment there are only three types of lines allowed:
comments
empty lines (white space is ok)
lines of the type "identifier=value", where <identifier> is any legal name for a shell variable and <value> is any legal content of same.
It is quite common to attempt the misuse of /etc/environment by adding all sorts of profile statements (export, if....then..., etc.), but all these will not work at all.
More or less: yes. You can and you even should use a plain editor (and which one would be better suited than the system editor itself?).
You are right. The "export" keyword makes the variable to become exported in forther opened subshells. It is like this:
Consider you start with "shell a", inside "shell a" you open "shell b" (they might be all all instances of the same shell, "ksh", i just named them differently here to address them).
Every environment variable set inside "shell a" will not be set inside "shell b" (=not be "exported"), unless you use "export" before opening "shell b". See here:
shell_a> varA="something"
shell_a> varB="other"
shell_a> export varB
shell_a> echo varA
something
shell_a> echo varB
other
shell_a> shell_b
shell_b> echo varA
shell_b> echo varB
other
shell_b> exit
shell_a> echo varA
something
shell_a> echo varB
other
Btw., it is not recommended to use "export var=value", because "export" is a keyword in its own right. you should use: