[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Behaviour of $(shell command args) is dangerously different from `co
Re: Behaviour of $(shell command args) is dangerously different from `command args`
Wed, 10 Apr 2013 14:05:43 -0400
On Wed, 2013-04-10 at 19:56 +0200, Vincent de Phily wrote:
> On Wednesday 10 April 2013 13:28:38 Paul Smith wrote:
> > On Wed, 2013-04-10 at 18:18 +0200, Vincent de Phily wrote:
> > > If the behaviour is expected (why ?), it would be usefull to explain the
> > > difference between `command` and $(shell command) in the info pages.
> > There is no difference between `command` and $(shell command), except
> > the order in which they're executed.
> > Remember that make will expand all make functions and variables in the
> > recipe FIRST, then pass the resulting text string to the shell for the
> > shell to execute. Make doesn't interpret the results of the functions
> > or variables itself.
> > (...)
> Thanks, this makes sense.
> Still an easy trap to fall into because Makefile syntax looks so much like
> shell that you quickly forget it isn't.
> The info pages probably point out that double-evaluation gotcha somewhere
> (I'll check tomorrow), but it's the kind of detail that you easily miss
> because it sounds obvious so you'll skip the section. Sigh...
I doubt this particular side-effect is discussed explicitly in the
manual, although the statement of how variables and functions are
expanded before the shell is invoked is definitely described... you're
left to connect the dots in this respect yourself, I believe.
> > In general you should never, and never need to, use $(shell ...) inside
> > a recipe command. You're already running a shell, so why?
> Probably because I'm not a fan of the `` syntax: I prefer the shell's $()
> syntax which is more readable and can be nested. Make's $(shell) syntax
> like a drop-in replacement.
There's no reason you can't use the shell's $() if you want, just double
the "$" to escape it from make: "$$(git log HEAD...)"
It's slightly annoying to need the extra "$", but overall it's less
typing than "$(shell ...)" after all :-).