[NTLUG:Discuss] OT - include bash script
Fred James
fredjame at fredjame.cnc.net
Tue Jan 5 16:06:29 CST 2010
Greg Edwards wrote:
> Is it possible to have a bash script include code from another file and
> maintain vars set by the parent script?
>
> example:
>
> parent script:
>
> message="hello world"
> $include child.inc
>
> child.inc:
>
> echo The message of the day is $message
>
> The $include directive pulls the code fine, but vars set by the parent
> are lost. In the above example $message is empty.
>
Greg Edwards
Not really sure what you want to accomplish, but ...
(A) if child.program could take a variable then this should do it ...
message="hello world"
./child.program "$message"
(B) or parent.program could set a environmental variable (line 1) and
child program could print it (line2) ...
(line 1) export MESSAGE_1="Hello world"
(line 2) echo "$MESSAGE_1"
... does any of that help?
Regards
Fred James
More information about the Discuss
mailing list