Export in bash - Unix

This is a discussion on Export in bash - Unix ; if i export a variable it exports to its child only. how can i export variables from child shell to parent?...

+ Reply to Thread
Results 1 to 5 of 5

Thread: Export in bash

  1. Export in bash

    if i export a variable it exports to its child only.
    how can i export variables from child shell to parent?


  2. Re: Export in bash

    lak wrote:
    > if i export a variable it exports to its child only.
    > how can i export variables from child shell to parent?
    >

    You can't.

    Robert

  3. Re: Export in bash

    On 2007-10-18, lak wrote:
    >
    > if i export a variable it exports to its child only.
    > how can i export variables from child shell to parent?


    You can't.

    However, you can have a script print a value and assign that to a
    variable in the parent:

    val=$( your_script )

    If you need to set more than one variable, have the script (or a
    command that allows formatting of its output) print assignment
    statements and use eval:

    eval "$( date +"year=%Y month=%m day=%d" )"


    --
    Chris F.A. Johnson, author |
    Shell Scripting Recipes: | My code in this post, if any,
    A Problem-Solution Approach | is released under the
    2005, Apress | GNU General Public Licence

  4. Re: Export in bash

    On Oct 18, 7:20 am, lak wrote:
    > if i export a variable it exports to its child only.
    > how can i export variables from child shell to parent?


    "Source" the child shell. That is, instead of executing it with:
    myshell
    run it in the local shell by prepending a period and space:
    . myshell

    --
    Fred Kleinschmidt


  5. Re: Export in bash

    fred.l.kleinschmidt@boeing.com writes:
    >On Oct 18, 7:20 am, lak wrote:
    >> if i export a variable it exports to its child only.
    >> how can i export variables from child shell to parent?

    >
    >"Source" the child shell. That is, instead of executing it with:
    > myshell
    >run it in the local shell by prepending a period and space:
    > . myshell
    >



    potentially dangerous. exit, for example, has significantly
    different effect if it is sourced vs. execed.

    scott

+ Reply to Thread