On 2018-02-02, Kenny McCormack <
gaz...@shell.xmission.com> wrote:
> In make, I'm trying to do something like:
>
> something:
> gawk 'BEGIN { print "hello, world" }' > something
>
> But it errs with a shell error message, because the above gets fed into a
> shell via the usual: sh -c '...'
But -c is a "clean" mechanism for passing through a piece of script!
It works for me verbatim. I copy and pasted that command into a Makefile
recipe, ran it, and the "something" file got created with "hello, world"
in it.
Are you using GNU Make?
Here is what a GNU make job looks like under strace:
4528 vfork() = 4530
4530 rt_sigprocmask(SIG_SETMASK, [], NULL, 8) = 0
4528 rt_sigprocmask(SIG_SETMASK, [], <unfinished ...>
4530 execve("/bin/sh", ["/bin/sh", "-c", "if true; then echo common
recipe"...]
The rule I have is something like:
target:
... commands ..
if true; then echo common recipe; fi
You can see that the whole command turns into a single argv[] element.
No single quotes are inserted into it; it is null-terminated C string
object in which the only character we cannot have is NUL, and nothing
requires escaping.
> mechanism, so you end up with:
>
> sh -c 'gawk 'BEGIN { print "hello, world" }' > something'
Not with GNU Make; maybe you have some make which does this?
If I add some single quotes to the command, I get this:
4570 vfork() = 4572
4572 execve("/bin/sh", ["/bin/sh", "-c", "if true; then echo 'common
recip"...]
It works perfectly.