It is currently Tue, 17 May 2022 01:44:02 GMT

Author Message
 export variables to calling shell in a shell-script


the (bash) shell-script

export blubber=blabber


should set the variable blubber to the value blabber in the shell, from
where I call the script...but it DOESN'T...any suggestions?

Thanks in advance,

Holger Hartmann

Sent via

 Thu, 24 Jul 2003 01:14:54 GMT   
 export variables to calling shell in a shell-script

You can't do it; a shell script cannot effect the environment of a parent.

The 'export' command actually is in the opposite direction to what you
want, marking a variable for export means that the variable will be copied
as part of the default environment for any _child_ shell run.

The only way you can solve this problem directly is to "source" the
script (ie: execute it within the current shell process).

In ksh/bash/sh you want the "." built-in command (man sh),
in csh it's "source".


- Show quoted text -

 Thu, 24 Jul 2003 02:24:36 GMT   
 export variables to calling shell in a shell-script

As Laura said, you can't do it that way, but consider this alternative:

function blubber2blabber {
    export blubber=blabber


    bash-2.04$ blubber2blabber

will set the exported variable.  functions work in the current
environment, as does dotting a file.


 Thu, 24 Jul 2003 12:44:55 GMT   
 export variables to calling shell in a shell-script
It shouldn't. It sets the variable in the shell
interpreting the script (which is a child of the one you
typed the name of your script into), making it available
to its children. But it is impossible for a script to
affect the environment of its parent. Can't be done.

 Fri, 25 Jul 2003 23:26:34 GMT   
   [ 4 post ] 

Similar Threads

1. export variables to calling shell in a shell-script

2. Exporting Enviroment Variables in shell scripts

3. Shell Variables: Shell prompt OK, script, NO.

4. file contents into variable, or global variable from shell script

5. Passing a variable from a Perl script to a shell script

6. Passing a variable between shell script and perl script

7. make - exporting shell variable to environment

8. exporting C shell variable

9. how do I export a shell variable

10. Adding/Changing an exported Shell Variable

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software