2

在 bash 文件中,我可以这样写:

my_program << EOF
Some test
More test
A lot of multi-line text
EOF

这将启动 my_program 可执行文件并通过管道将三行(或更多)文本传递给它。

现在我想在 Makefile (GNU make) 中做同样的事情。我没有找到标准解决方案,它是这样解决的:

LaunchMyProgram:
    echo -en "Some test\\nMore test\\nA lot of multi-line text\\n" | my_program

但这看起来非常难看。有没有更精细的解决方案?

4

1 回答 1

2

是的,这很丑陋,但你无能为力。make将每一行作为其自己的 shell 脚本执行,除非该行以\续行字符结尾;但随后换行符被剥离。这有点清洁:

all:
    printf 'hi\n\
    there\n\
    how\n\
    are\n\
    you'

通常我会echo在这里使用,但printf在处理转义字符时更便携。

于 2013-01-16T20:35:18.460 回答