LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 04-18-2008, 04:31 PM   #1
concoran
Member
 
Registered: Jun 2001
Location: 28N,82W
Distribution: XP,Ubuntu 9
Posts: 473

Rep: Reputation: 30
exporting environment variables from a file?


I have some 10 environment variables that I repeatedly need to export, every time I need to do something. And typing 'export varname' ten times for each session is rather tedious. So I put those in a file abc.sh and changed mode to 777 to execute. But after I execute that shell script, the variables don't seem to have exported (when I do 'env | grep VARNAME).
Is it possible to export vars from shell script. If so, how?

Thanks in advance.

Also, as a side question, how to find (from terminal) if this is a redhat or a fedora or debian or any other distro? I did uname -a, and it doesn't mention distro name except the kernel version.

Last edited by concoran; 04-18-2008 at 04:34 PM.
 
Old 04-18-2008, 04:39 PM   #2
jailbait
LQ Guru
 
Registered: Feb 2003
Location: Virginia, USA
Distribution: Debian 12
Posts: 8,340

Rep: Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550Reputation: 550
When you export variables their value applies to the shell that does the export and all subshells. They do not apply to the parent shell. When you issue the command a subshell executes the command. The variables are set for the subshell and then lost when the subshell exits back to the shell where you issued the command.

To set the environmental variables for your shell put the export commands in /home/user/.bashrc or /home/user/.profile or home/user/.bash_profile, whichever your distribution uses.

---------------------
Steve Stites
 
Old 04-18-2008, 04:40 PM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Hi,

You should parse the file, not execute it.

If you execute it all is done in a new shell, once the program is finished that shell is closed and all settings are 'lost'. When you parse a file, all is done in the current shell (the one you typed the command in).

Parsing:
. file (that's a dot followed by a space followed by the filename).

You also don't need the execute permissions when you parse, 644 (or better 640) is enough.

About the other question: Most distro's create a file in /etc that has the word release in it. It will contain some distro related info.

Hope this helps.
 
Old 04-18-2008, 04:40 PM   #4
bigrigdriver
LQ Addict
 
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian stable
Posts: 5,908

Rep: Reputation: 356Reputation: 356Reputation: 356Reputation: 356
Cat /etc/issue to see the distro name.
 
Old 04-19-2008, 05:49 PM   #5
concoran
Member
 
Registered: Jun 2001
Location: 28N,82W
Distribution: XP,Ubuntu 9
Posts: 473

Original Poster
Rep: Reputation: 30
Thanks Druuna, it worked.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
exporting variables gecoool Programming 2 10-25-2005 01:17 AM
G++ environment variables, rerouting output, file listings and PIDs Kawahee Programming 7 09-19-2005 12:40 PM
how to refer to environment variables in an ant file irfanhab Programming 1 09-12-2005 06:15 AM
Exporting variables through scripts rammya Programming 1 04-14-2004 10:24 AM
exporting global variables neo77777 Programming 6 09-18-2002 01:46 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 06:45 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration