[aklug] Re: bash die

From: Christopher Howard <choward@indicium.us>
Date: Wed Sep 15 2010 - 16:36:42 AKDT

On 09/15/2010 04:24 PM, Arthur Corliss wrote:
> On Wed, 15 Sep 2010, Christopher Howard wrote:
>
>> I was of the understand that make doesn't preserve variable assignments
>> across commands, which means you couldn't do something like this:
>>
>> VAR=`ls`
>> echo $VAR
>>
>> If I'm wrong, write me a Makefile that proves it.
>
> There's more than one way to skin that cat. Here, for instance, is a
> pseudo-recursive ls written in make:
>
> DIR ?= '.'
> TARGETS := $(shell ls $(DIR))
>
> default:
> @echo
> @echo "Listing files in $(DIR):"
> @echo
> @echo $(TARGETS)
> for tgt in $(TARGETS) ; do \
> ( test -d $(DIR)/$$tgt&& $(MAKE) DIR=$(DIR)/$$tgt ) \
> ; done
>
> This relies on calling itself recursively and overwriting variable defs on
> the command line.
>

That /so/ does not count. That's some very impressive coding there (no
sarcasm) but a Makefile that calls itself recursively is definitely not
preserving assigned variable values across commands.

>> And how do you write functions in a Makefile?
>
> Those are just rules, basically, but you can also use 'define' to create
> macros as well.
>
> --Arthur Corliss
> Live Free or Die
> ---------
> To unsubscribe, send email to<aklug-request@aklug.org>
> with 'unsubscribe' in the message body.
>

Since you didn't provide any super-fancy example to go with that, I
can't say much. But somehow I'm guessing writing a library of bash
functions is a lot easier that writing a library of Makefile targets
pretending that they are bash functions.

-- 
Christopher Howard
http://frigidcode.com
http://theologia.indicium.us
---------
To unsubscribe, send email to <aklug-request@aklug.org>
with 'unsubscribe' in the message body.
Received on Wed Sep 15 16:36:52 2010

This archive was generated by hypermail 2.1.8 : Wed Sep 15 2010 - 16:36:52 AKDT