how can i change the value of a environment variable through shell script ?
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
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.
No, it's not possible to set anything in the environment above whatever command is running. To be able to do so would be a big security risk.
The only real way I know of to set your environment through a script is to have it sourced by your start-up script, which in essence makes it part of that start-up script.
To transfer information between scripts you need to use a temporary file or perhaps a fifo.
And my next requirement is to start another script (script B) in true condition. At the same time i need to exit from the current script (above mentioned script)
Sourcing the file back into your first script does no good. All it does is set the environment of that script, meaning it's still unavailable outside of it. In order to set the environment of the shell, it needs to be sourced by the shell itself.
Or, since your purpose is to set the environment of the second script, export it to a file with the first script, then source that file into the second script.
Export the variables you define in .bashrc. The file is sourced so it doesn't run in a subshell. Export moves variables from normal memory to environmental memory.
In your first post, you had a space after the equals sign. You would be clearing the variable instead and then running the true command.
If you intend for .bash_rc to be used only in certain scripts, then source .bash_rc in the beginning of the scripts that use it.
Last edited by jschiwal; 02-13-2010 at 08:11 PM.
Reason: spelling
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.