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.
I have a usb flash jumpdrive that I use to carry all of my current projects. What I'm trying to do is write a shell script for it that sets up several environment variables that are needed by my development environemtn such as CVSROOT, Java dependencies, Editors, etc. The problem is that I can't seem to get the variables to export.
What am I missing? I'm not doing anything different that what some of my start up scripts do so how is running them from a console window any different?
You're running a script, then testing the variables from the current shell, yes?
When that script ends, the shell which ran the script also closes, and you're back to your old environment.
Any application which needs to use those variables needs to be spawned from the same shell which created the variables, or a child of that shell.
To test this, add the line "xterm &" at the end of your script.
Then test your environment from that xterm. You'll probably see the correct values.
Another option...
instead of executing the script (which opens a new shell), source it from your current shell:
source envsetup.sh
or
. envsetup.sh
You're running a script, then testing the variables from the current shell, yes?
Thats right.
Quote:
When that script ends, the shell which ran the script also closes, and you're back to your old environment.
Any application which needs to use those variables needs to be spawned from the same shell which created the variables, or a child of that shell.
Oh, that explains it.
Quote:
To test this, add the line "xterm &" at the end of your script.
Then test your environment from that xterm. You'll probably see the correct values.
No that didn't quite work the way I had hoped. When the xterm window pops up, I check it with something like: echo $CVSROOT and I get my old CVSROOT not the new one that the shell supposed to have set.
The only way I was able to get the new variables to take is if I open a terminal window, change my shell to sh then source the file like you suggested:
bash-2.05b$ sh
sh-2.05b$ source envsetup.sh
sh-2.05b$ echo $CVSROOT
:local:/mnt/diskonkey/src ## Correct new CVSROOT
This is fine but hoping there is a bit smoother solution. I like the idea of a new xterm window poping up ready to go. That way I can start the script by double clicking on the icon in a file explorer and a new window pops up with my environment ready to go.
That's weird....I copied and pasted your script exactly as you have it here, added xterm, and the variables work fine for me.
You're sure you typed "echo $CVSROOT" in the new xterm window rather than the original shell window?
Thats right I typed it in the XTERM window as opposed to the shell window. It is rather weird.
What I didn't mention before was that this is a unversity computer that I've been trying to get this to work on. Once I got home, it worked just like I hoped -- plugged in the usb stick, an icon popped up on my desktop, I double clicked on envsetup.sh, xterm came up, and all of my environment variables were initialized and ready to go. When I'm on campus again I'll check it and see if I can get it to work properly.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.