Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
"However, these changes do not persist after the script terminates.
Is there any way to accomplish this?"
In a word, no.
Variables can be set for the current process and subprocesses of the currecnt process. They cannot be set for a parent process. So in your example you enter a script name as a command in bash. Bash starts a subprocess to run the command. The subprocess can access variables inherited from its parent, make changes to those variables, and create new variables. When the subprocess ends, control Is passed back to the parent process and any variable changes made by the subprocess disappear. Upon return, the parent process' variables are exactly the same as they were before the subprocess was created.
If you want to make the variables universal I suggest that you create a config file and keep the variables there.
I stand corrected. Tinkster's idea of running the script with the source command will work because the source command will run the command as the current process instead of a subprocess.
Hmmm, is there any way to set these settings globally?
The problem is that it's a distributed systems assignment, and I'm running processes in different terminals that rely on environment variables that are constantly changing.
i.e. I have to frequently change an environment variable that stores port numbers.
It's not the way I would of designed the system, but the university wrote the project specifications :P
You can set them on a per-user-login basis, using ~/.bash_profile, or on a system-wide per-login basis, using /etc/profile. There is no way to change the environment variables of another running process.
How does a shell determine which scripts in /etc/profile.d to execute? In my /etc/profile.d, there are a bunch of tcsh scripts, but no bash scripts. Or do they try to execute any they find?
Originally posted by Matir How does a shell determine which scripts in /etc/profile.d to execute? In my /etc/profile.d, there are a bunch of tcsh scripts, but no bash scripts. Or do they try to execute any they find?
Yep ...
Anything that's in there and executable should be sourced from
/etc/profile
Code:
From /etc/profile
--------8<--------8<--------8<--------8<--------8<--------8<--------
# Append any additional sh scripts found in /etc/profile.d/:
for file in /etc/profile.d/*.sh ; do
if [ -x $file ]; then
. $file
fi
done
That's odd. While I know gentoo has a long history of doing things its own way, I find no references to profile.d in /etc/profile. In fact, the only ones I find are within /etc/profile.d itself, and a reference to /etc/profile.d/bash-completion in /etc/skel/.bashrc.
Seems a bit odd. I wonder if all distros (are supposed to) use profile.d.
SuSE, and DeadRat seem to make use of it, I just verified that on
two servers I have access to. And the roll-your-own distro that's
in use here has it, too.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.