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

Re: exported shell variables and scope



On Wed, Jul 25, 2001 at 01:37:25PM -0700, Mike Markley wrote:

> (Please don't Cc: me on list replies :)
> 
> On Wed, Jul 25, 2001 at 04:27:25PM -0400, Dale Scheetz <dwarf@polaris.net> spake forth:
> > If I explicity place the variable declaration (without export!) before any
> > target in the makefile, this variable is visible to other commands in the
> > makefile. Why does "sourcing" those declarations change their scope, or is
> > it their placement within a target?
> 
> When you define a variable in a Makefile, it's defined within that make
> instance. When make spawns off other programs, it sticks those variables
> into the subshells' environments. So, when you do a "FOO = bar" in your
> makefile, then a "cp foo $FOO" in a rule, make inserts the variable FOO
> into the subshell running the "cp".

This is only true for variables which are in the environment in which make(1)
is executed.  Setting a make variable does not automatically pass that variable
into subshell environments.  See the example I posted in another thread, and
the make documentation.

-- 
 - mdz



Reply to: