M
M
Matvey2016-03-25 12:40:05
linux
Matvey, 2016-03-25 12:40:05

Where can I find the environment variable file?

After reading a lot of material, I still haven’t figured out where the file is located in which the environment variables are written (on many sites they indicated the paths on which I have nothing) and whether there is such a file at all or in the file it is only written which variables to create at the start of the process and they are stored in RAM? Is it possible to open this file for reading from my program and change some values ​​in it or add new ones (not using setenv, putenv, but manually appending to the file)? What will happen?
Ps I googled for a very long time and honestly, but I could not find a clear answer, please explain on your fingers

Answer the question

In order to leave comments, you need to log in

2 answer(s)
P
Pavel Selivanov, 2016-03-25
@JavaBoy

Almost every distribution uses pam_env, which reads settings from /etc/security/pam_env.conf and /etc/environment. Usually it is enabled for login, ssh, cron, and thus the variables set in these files will be visible to all processes launched from the console or by schedule.
In addition, variables can be set in local and global shell configs (/etc/profile, /etc/profile.d/*, /etc/bashrc, ...) , but this will only affect processes started from the shell.
There may also be some distribution-specific options, for example, Gentoo has a system-wide /etc/env.d/*
But in general, it depends on the way the software is launched, which needs to be fed a variable. Maybe you need to specify something in its configs. To pass specific variables to daemons, Debian typically uses /etc/default/{service_name}, while RedHat uses /etc/sysconfig/{service_name}. But it's worth checking the daemon's init file to see if it reads these configs.

A
AVKor, 2016-03-25
@AVKor


I googled for a long time and honestly, but I could not find a clear answer
Specially checked up as the statement this looks, to put it mildly, strange:
google://environment+variables+linux
Mass of relevant links on the first page.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question