LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   exporting environment variables from a file? (https://www.linuxquestions.org/questions/linux-newbie-8/exporting-environment-variables-from-a-file-636320/)

concoran 04-18-2008 04:31 PM

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.

jailbait 04-18-2008 04:39 PM

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

druuna 04-18-2008 04:40 PM

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.

bigrigdriver 04-18-2008 04:40 PM

Cat /etc/issue to see the distro name.

concoran 04-19-2008 05:49 PM

Thanks Druuna, it worked.


All times are GMT -5. The time now is 11:42 PM.