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.
Hey, I'm trying to figure this one out. Maybe you can help me. Here's what I got:
-----------------------------
#!/bin/bash
echo "Enter the partition where LFS is to be installed (/mnt/lfs):"
read LFS
if [ ! $LFS ]
then
LFS="/mnt/lfs"
fi
export LFS
-----------------------------
Now, when I run this, it works fine, however, when it exits back to the shell, I type in "echo $LFS" and it prints an empty line. It's my undestanding that LFS should be a global variable and should be available after the program exits. Am I wrong?
Actually, I haven't yet started the installation of LFS, this is just a generic question regarding global variables. But, yes, my plans are to create an automatic install script. Why? Because I've gone through the whole thing 4 times now, and it's getting boring.
Originally posted by dtheorem Actually, I haven't yet started the installation of LFS, this is just a generic question regarding global variables. But, yes, my plans are to create an automatic install script. Why? Because I've gone through the whole thing 4 times now, and it's getting boring.
There is already a full project towards automating the build, you can find links through the LFS homepage. There is also a Makefile available at Christophe Devine's (?) home directory on the main LFS server.
To answer your question more fully: the script is launched in a new instance of the shell, and thus is not affecting your current instance. However, any script run from within that sub-shell will have that environmental variable ( as far as I know ).
You seem to be misunderstanding how environment variable works. They are not global to the system. Rather, each process inherits a copy of the parent's envvars. So in your case, when the child script exits, any envvars it creates are also lost.
Thank-you for your explanations. They were very helpful. In regards to ALFS, I've tried many times to install it, but I run Mandrake 9.2 and there's a universal law that says ALFS does not install under Mandrake 9.2. We always get an error with libxml2. Anyway, my script is teaching me a lot about bash programming, which is always a plus.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.