在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
但这看起来很丑。还有更好的解决方案吗?
最佳答案
是的,这很丑陋,但你对此无能为力。 make
将每一行作为自己的 shell 脚本执行,除非该行以 \
延续字符结尾;但随后换行符被删除。这更干净一点:
all:
printf 'hi\n\
there\n\
how\n\
are\n\
you'
通常我会在这里使用 echo
,但 printf
在处理转义字符时更便携。
关于pipe - 将多行数据传递到 Makefile 中的管道,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14363500/