Setting global system variables
Hello everyone.
I was wondering how to set environmet variables that are globally accessible for all processes/users that are in the system. I saw that you can do this by staticly adding line to /etc/profile, but I want to be able to do this "on the fly" and preferably from a c-program or secondly from a shell script. The problem right now is that when I create a variable in one shell (read one memory space) it is only visible to that shell. How are the global variables set so that everyone can access them? I hope I am making some sence to you out there. Sincerly Kristoffer Nordström |
Variables are set when user logs in (or runs a terminal emulator etc). There's no way provided to change variables in all sessionsa fter they're run. What you can think of is editing files in /proc/ (process files), but it may not work and cause problems.
|
Hmm .. I was thinking of using proc earlier.. can I just create new files there (read: in the RAM) or do I have to use the existing file structure?
Sorry if this seems a bit neewbish but we alll have to learn the hard way. Sincerly Kristoffer Nordström |
You need to use the existing files you want to change something - proc is an interface between the kernel and user space and it requires proper formats.
|
Thanks for the reply. Well its back to the drawing board then.
For now I have written a library that "sets" the "variable"-information in /tmp/THISVARIABLE to have a common point for all shells and processes to store and retrieve. However I will look further into the possibility to use some form of shared memory where variables can be set. HopeI dont have to write the damn thing myself. Anyway thanks for the help. Sincerly Kristoffer Nordström |
Re: Setting global system variables
Quote:
Code:
source filename.sh Code:
./filename.sh For more complex situations where you need to execute a new process to create environment variables, then they will not exist after the process terminates. One trick to get around this is to have the process write its output to stdout, then "backtick" or "$(...)" the execution of the script into your current shell. A simple example -- assume script is named "setup_env.sh" (this is just an example, for something this simple you would just "source" a script.) Code:
#!/bin/bash Code:
`./setup_env.sh` Code:
bash-2.05b$ echo "$aaa $bbb $ccc" |
All times are GMT -5. The time now is 12:53 AM. |