Register a domain and help support LQ
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


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

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 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 05:34 PM.
Old 04-18-2008, 05:39 PM   #2
LQ Guru
Registered: Feb 2003
Location: Blue Ridge Mountain
Distribution: Debian Wheezy, Debian Jessie
Posts: 7,671

Rep: Reputation: 230Reputation: 230Reputation: 230
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, 05:40 PM   #3
LQ Veteran
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381Reputation: 2381

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).

. 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, 05:40 PM   #4
LQ Addict
Registered: Jul 2002
Location: East Centra Illinois, USA
Distribution: Debian Squeeze
Posts: 5,846

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

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


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 02:17 AM
G++ environment variables, rerouting output, file listings and PIDs Kawahee Programming 7 09-19-2005 01:40 PM
how to refer to environment variables in an ant file irfanhab Programming 1 09-12-2005 07:15 AM
Exporting variables through scripts rammya Programming 1 04-14-2004 11:24 AM
exporting global variables neo77777 Programming 6 09-18-2002 02:46 PM

All times are GMT -5. The time now is 12:18 AM.

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