【发布时间】:2016-06-01 16:19:01
【问题描述】:
有人知道如何在食谱上使用此处文档重定向吗?
test:
sh <<EOF
echo I Need This
echo To Work
ls
EOF
尝试使用通常的反斜杠方法(基本上以单行中的命令结束)时,我找不到任何解决方案。
理由:
我有一组多行配方,我想通过另一个命令(例如 sh、docker)进行代理。
onelinerecipe := echo l1
define twolinerecipe :=
echo l1
echo l2
endef
define threelinerecipe :=
echo l1
echo l2
echo l3
endef
# sh as proxy command and proof of concept
proxy := sh
test1:
$(proxy) <<EOF
$(onelinerecipe)
EOF
test2:
$(proxy) <<EOF
$(twolinerecipe)
EOF
test3:
$(proxy) <<EOF
$(threelinerecipe)
EOF
我希望避免的解决方案:将多行宏转换为单行。
define threelinerecipe :=
echo l1;
echo l2;
echo l3
endef
test3:
$(proxy) <<< "$(strip $(threelinerecipe))"
这可行(我使用 gmake 4.0 和 bash 作为 make 的外壳)但它需要更改我的食谱,而且我有很多。 Strip 从宏中删除换行符,然后所有内容都写在一行中。
我的最终目标是:proxy := docker run ...
【问题讨论】:
-
sh -c
'put your commands here'怎么样? -
@e0k 我添加了上下文
-
你的具体例子最好写成
printf 'I need this\nTo work\n'; ls -
@e0k 如果您仍然认为这个 Q 是重复的,请再次投票。这样它就不会老化。
标签: bash shell makefile gnu-make heredoc