I think you have a misconception about how Linux environment variables work. Environment variables for a running shell are only defined for that instance of the shell that is running. They have no meaning or relevance outside of that. If you change the $PATH variable in a shell you are using, that change will only have an effect on that instance of the shell, not on others that you may have running.
When a shell starts up and the user logs in, environment variables can be set by various shell scripts, which may define default environment variables on a system-wide or per-user basis. For bash
, these are scripts like /etc/profile
(system wide) or ~/.bash_profile
or ~/.bashrc
(specific to the user). As far as I know, there is no way to determine from a running shell where a particular variable was set - you would need to check those files.
Another concept you should be aware of is of exporting variables. The export
command in bash
can be used to flag which variables should be exported to new sub-shells that the running shell may create.
Also, be aware that environment variables are specific to specific shell programs, they are not global for the Linux system. So, variables for bash
(which I have been using as an example) may be different to those used in csh
(although there may be some similarities) and/or they may be set to different defaults.
printenv
command. There are some commands for defining variables as user-wide, system-wide or local (session-wide), but I couldn't find how to list them. Note: I am a new Linux user. – demirod Mar 19 '21 at 16:27