help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] Is there a way to make variables used in a sourced scrip


From: Dan Douglas
Subject: Re: [Help-bash] Is there a way to make variables used in a sourced script local to the script being sourced, so that the variables will not be available in the script where the "source" command is called?
Date: Sun, 7 Jun 2015 23:01:16 -0500

On Sun, Jun 7, 2015 at 10:43 PM, Peng Yu <address@hidden> wrote:
> On Sun, Jun 7, 2015 at 9:44 PM, Dan Douglas <address@hidden> wrote:
>> On Sun, Jun 7, 2015 at 9:11 PM, Peng Yu <address@hidden> wrote:
>>> Is there a way to make variables used in a sourced script local to the 
>>> script
>>> being sourced, so that the variables will not be available in the script
>>> where the "source" command is called?
>>
>> Don't put code outside of functions in sourced scripts. Put all library code
>> into functions, source the file, then call the functions.
>
> But then the function is available in the script where the source
> command is called. I don't want this function either.

What are you trying to do exactly? There's not a lot that can be done about
that since there's only one namespace.

In a very large program there might be a file that sources another and then
calls a function to clean up unused functions (and itself) with `unset -f` when
finished with them. That's about the best you can do.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]