[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: embedded newlines in shell function variable expansion
From: |
Byrnes, Robert |
Subject: |
RE: embedded newlines in shell function variable expansion |
Date: |
Fri, 9 Oct 2020 18:00:58 +0000 |
> My suspicion is that it's a difference between your /bin/echo command and
> your shell's builtin echo command.
>
> In the first case (with the ";") because there's a special character in the
> command GNU make will run a shell like this:
>
> /bin/sh -c 'echo ... ; '
>
> and the shell's built-in echo will be used (if it has one, which most shells
> do).
>
> In the second case (without the ";"), there's no special character and so GNU
> make runs the fast path which invokes the echo command directly, not using a
> shell, and so it will use your PATH to find an "echo" program and run that.
>
> If you change both commands to use /bin/echo explicitly, do they work the
> same way?
The behavior doesn't change if I use /bin/echo for both commands.
strace shows the subprocesses exactly as you describe, but the newlines have
already been stripped (by make, I presume) before the shell is invoked:
----------------
execve("/usr/bin/make", ["make", "ENTRIES=\nblartz\nblurfl\n"], 0x7ffdac2aff40
/* 72 vars */) = 0
[pid 144497] execve("/bin/sh", ["/bin/sh", "-c", "/bin/echo blartzblurfl ; "],
0x7ffd98ee6bc0 /* 72 vars */) = 0
[pid 144497] execve("/bin/echo", ["/bin/echo", "blartzblurfl"], 0x1631fb0 /* 71
vars */) = 0
[pid 144498] execve("/bin/echo", ["/bin/echo", "blartz\nblurfl\n"],
0x7ffd98ee6bc0 /* 72 vars */) = 0
----------------
For reference, here's the modified Makefile ...
----------------
FOO := $(shell /bin/echo $(ENTRIES) ; )
BAR := $(shell /bin/echo $(ENTRIES) )
all:
@echo FOO = $(FOO)
@echo BAR = $(BAR)
.PHONY: all
----------------
And this is how to reproduce the behavior ...
----------------
bash$ make 'ENTRIES=
blartz
blurfl
'
FOO = blartzblurfl
BAR = blartz blurfl
----------------
Thanks,
--
Bob