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: Mon, 8 Jun 2015 00:23:55 -0500

On Sun, Jun 7, 2015 at 11:26 PM, Dave Rutherford
<address@hidden> wrote:
> On Sun, Jun 7, 2015 at 11: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.
>
> You don't want the variables in your namespace and you don't
> want the functions either? Sounds like you'd be better off calling
> the other script as an independent entity, not using `source'.

Yeah there's not much reason to avoid the subshell if you want NO
side-effects in the calling script.



reply via email to

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