bug-make
[Top][All Lists]
Advanced

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

Re: escaped newline in macro expansion in command line


From: Paul Smith
Subject: Re: escaped newline in macro expansion in command line
Date: Fri, 24 Dec 2021 12:02:33 -0500
User-agent: Evolution 3.36.5-0ubuntu1

On Fri, 2021-12-24 at 10:45 +0000, Humm wrote:
> Consider the Makefile:
> 
>         .POSIX:
>         M = word
>         all:
>                 echo ${M:word=a\
>                 b}
> 
> I believe, as the escaped newline is in a command line, the expected
> behavior is to let the macro expand to it, and thus to run the
> command
> 
>         echo a\
>         b
> 
> with output `ab`.  The actual output is `a b`.

I understand what you're saying, but it's not true that the expected
behavior is to run the command:

  echo a\
  b

In your example the backslash is part of a variable expansion: it's
INSIDE the variable expansion so it will be handled by make as part of
expanding the variable and won't ever be passed to the shell.

It's handled as if you wrote:

  M = word
  _X = ${M:word=a\
  b

  all: ; echo ${_X}

Where you would expect to see "a b".

There is an argument to be made that the backslash should be managed as
if it were part of a command line and not part of a variable assignment
because it appears in a recipe, even though it's part of a make
variable expansion.  If the backslash were handled that way then make
would see this:

  echo ${M:word=ab}

after the backslash/newline was removed and it would run the command:

  echo ab

which is still not

  echo a\
  b

but would give equivalent output in this case.  I don't know offhand
what the right behavior is.  No version of make I've been able to find
actually works this latter way, removing the backslash first.





reply via email to

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