|
Home > Archive > Unix Programming > October 2007 > Export in bash
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
|
|
|
| if i export a variable it exports to its child only.
how can i export variables from child shell to parent?
| |
| Robert Harris 2007-10-18, 1:25 pm |
| 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
| |
| Chris F.A. Johnson 2007-10-18, 1:25 pm |
| 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 | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| fred.l.kleinschmidt@boeing.com 2007-10-19, 7:20 pm |
| On Oct 18, 7:20 am, lak <lakindi...@gmail.com> 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
| |
| Scott Lurndal 2007-10-22, 7:22 pm |
| fred.l.kleinschmidt@boeing.com writes:
>On Oct 18, 7:20 am, lak <lakindi...@gmail.com> wrote:
>
>"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
|
|
|
|
|