对于我的Makefile中的以下行,我得到了错误
Syntax error: end of file unexpected (expecting "then")代码:
if [ ! -d upload-api/app-router/ ] then
git clone someRepo upload-api/app-router/
fi我试过在括号后面用分号,但仍然有同样的错误
发布于 2018-08-21 08:46:36
您需要在下一行或使用分号。
if [ ! -d upload-api/app-router/ ]
then或
if [ ! -d upload-api/app-router/ ];then发布于 2018-08-21 18:25:04
在makefile的上下文中,我看到了两件事。
首先,在then之前需要一个分号或换行符。if的Shell语法类似于:if commands... ; then commands... ; fi (这里的任何分号都可以用换行符替换)。
其次,当make执行一个菜谱时,它会在一个单独的shell实例中运行菜谱的每一行,如果任何一行出现错误,则停止执行。实际上,它正在运行:
sh -c 'if [ ! -d upload-api/app-router/ ]; then' &&
sh -c 'git clone someRepo upload-api/app-router/' &&
sh -c 'fi'...which是第一行的语法错误,无论分号是否存在,因为if永远不会完成。
因此,对于makefile菜谱,您需要让make知道它应该将整个if ... fi块看作一行。例如,使用反斜杠表示行继续,并在适当的位置使用分号,因为shell不会看到任何换行符。
my-target:
↦ if [ ! -d upload-api/app-router/ ] ; then \
↦ git clone someRepo upload-api/app-router/ ; \
↦ fi这很快就会变得笨拙,所以我最喜欢的解决方案通常是将usually脚本放在一个单独的文件中,然后从您的菜谱中运行该文件。
https://askubuntu.com/questions/1067414
复制相似问题