[NTLUG:Discuss] OT - include bash script

Hank Ivy hankivy at hot.rr.com
Tue Jan 5 17:48:06 CST 2010


Yes.  But you need to export (or is it set?) the vars that you do not want to 
lose.

Or there is the . command.

On Tuesday 05 January 2010 03:22 pm 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.
> 

-- 
Hank Ivy

GPG Fingerprint:
1A0F E1CB 0160 0069 7C19 4B00 911C 92E8 F8B0 4C7C



More information about the Discuss mailing list