how to export shell environment variables to the primary environment?

how to export shell environment variables to the primary environment?

Post by Alan Wein » Sat, 29 Apr 1995 04:00:00



I call a shell proc from the main session.  The shell sets some variables
(set x=test).  Is it possible to have the environment variables stay, so
that after the shell exits, the variables are part of the main
environment?
 
 
 

how to export shell environment variables to the primary environment?

Post by Tony Nugen » Mon, 01 May 1995 04:00:00



>I call a shell proc from the main session.  The shell sets some variables
>(set x=test).  Is it possible to have the environment variables stay, so
>that after the shell exits, the variables are part of the main
>environment?

No.  Spawned shells (eg, in a #!/bin/sh script) cannot pass
shell variables back to the parent shell.  (Not even environment
variables set with "setenv).

The way around this is to *source* the script from the current
shell.

I'm sure there's an explaination for this in the unix FAQ.  It's
a similar problem to why you can't write a shell script to change
to another directory and expect the parent shell to have changed
directories as well.  (Sourcing the script or using an alias are
the solutions).

Cheers
Tony
 ______                    , _                                  
 (_) |                     /|/ \                                
     | __   _  _            |   |          __,  _   _  _  _|_  
   _ |/  \_/ |/ |  |   |    |   |  |   |  /  | |/  / |/ |  |    
  (_/ \__/   |  |_/ \_/|/   |   |_/ \_/|_/\_/|/|__/  |  |_/|_/  
                      /|                    /|                  

                       '                     '                  

 
 
 

1. make - exporting shell variable to environment

using bash-2.05, linux, make-3.79.1

I have a makefile which makes a program which runs in either serial mode or
parallel (multithread) mode, according to a flag I edit at the top
of the Makefile (the flag being the number of processes I want to run,
OMP_NUM_THREADS=8 say)
.
The make and compilation goes one way or another according to ifdefs etc.

WHen the program runs it needs to know from the environment, the number
of processes it's to run. So I need to export OMP_NUM_THREADS back to the
environment from which I called make.

The command "export" in a Makefile only passes an environmental variable to
sub-makes.
I can't figure out how to get it back to the original environment.

I tried getting the Makefile to source a file ".profile" in the
same directory as the Makefile. I echo out the values, which are
correct when .profile is sourced, but the values aren't in the environment
when the Makefile executes.

Any ideas anyone?

Thanks Joe

--
Joseph Mack, NA3T, FM05lw EME(B,D)
AZ_PROJ map server at http://www.wm7d.net/azproj.shtml

2. Can Linux IP stack be "MS Proxy-fied"?

3. c shell script; Howto use environement variables to build environment variables and take their value

4. Linux on an IBM Thinkpad...

5. Difference between shell variables and environment variables!

6. configure: error: not found - you need to install kdelibs first...

7. difference between shell variable and environment variable

8. patch no 23.3493 for Solaris 2.9

9. Why does the cgi environment not inherit environment variables?

10. getting environment variables from c shell using Bourne shell

11. How to export environment variable to parent?

12. setting/ exporting environment variable in a script file

13. export an environment variable