[NTLUG:Discuss] OT - include bash script

Chris Cox cjcox at acm.org
Tue Jan 5 16:20:19 CST 2010


On Tue, 2010-01-05 at 15:22 -0600, 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.
> 

source it in

message="hello world"
. child.inc

# that is dot followed by space followed by script to source in







More information about the Discuss mailing list