Can we directly edit "/etc/environment" file in AIX using vi ?

Hi

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

please suggest.

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.

@ blackrageous

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.

please provide your comments.

thanks

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:

  1. comments
  2. empty lines (white space is ok)
  3. 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.

I hope this helps.

bakunin

1 Like

Thanks for your time. I got you.

Let me give you an example, so that you can correct me if i misunderstood.

/etc/profile
and /etc/environment
both works in the same way. And we can edit with "vi editor"

my example:

If i want to make some changes on /etc/environment
i just need add the below line

HISTSIZE=5000

or
i can edit /etc/profile

export HISTSIZE=5000

both works in the same way. please correct me if am wrong.

Thanks,

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:

var=value
export var

instead.

I hope this helps.

bakunin

1 Like