Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's 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'm a Linux newbie, so I'm probably overlooking something obvious. I'm running Ubuntu 8.04 and trying to send updates to a SOLR server via a bash script.
Problem is, when I call the import script it gives me the error message:
You need to set the SOLR_HOME environmental variable before running this script.
Now, I can set SOLR_HOME using the export command, but the bash script still can't see it. The code in the bash script generating the error is this:
if [ -z "$SOLR_HOME" ]
then
echo "You need to set the SOLR_HOME ... "
fi
Strangely, the import script does run (without warnings) if I call it using a Perl script with the line:
`export SOLR_HOME=[directory];./import.sh`
So: Why would a child process not see an environment variable exported by its parent process? And why would commands issued from the command line fail while the same commands sent from a Perl script succeed?
After that, I can enter
echo $SOLR_HOME
and see the value I've just established; or I can enter env and see SOLR_HOME in the list. The script warns me to set the SOLR_HOME environment variable anyway.
I run the import script with the command:
sudo ./import.sh
the same command without "sudo" doesn't work: the shell just sits for a minute and then gives me another prompt. No warnings about permissions or anything. This is also puzzling behavior, but I'm not sure it's related.
So, that's the point: the "sudo" command does not preserve the environment, that is, it does not preserve variables values.
Give a look at the sudo manpage, the -E option and "SECURITY NOTES" describe how to deal with this. You can change your sudoers file to preserve the environment, or you can insert your environment modifications in a script, say do_all.sh, that called with 'sudo do_all.sh' changes the environment and eventually calls ./import.sh
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.