Bash Makefile:语法错误/bin/sh:-c:语法错误:文件意外结束
我有一个简单的Makefile:Bash Makefile:语法错误/bin/sh:-c:语法错误:文件意外结束,bash,makefile,Bash,Makefile,我有一个简单的Makefile: git_repo := some_git_repo repo: if [ -v $(git_repo) ]; then \ echo "exists!" \ else \ echo "not exist!" \ fi; clean: repo 运行makeclean时出现错误: /bin/sh: -c: line 4: syntax error: unexpected end of file mak
git_repo := some_git_repo
repo:
if [ -v $(git_repo) ]; then \
echo "exists!" \
else \
echo "not exist!" \
fi;
clean: repo
运行makeclean
时出现错误:
/bin/sh: -c: line 4: syntax error: unexpected end of file
make: *** [repo] Error 2
我不太确定这个错误的原因是什么。我已经反复检查了无数次语法,检查了许多不同的StackOverflow问题,甚至尝试在
repo
规则下单独运行bash代码,效果很好。我做错了什么 反斜杠会将所有shell行连接成一条长行,这意味着您需要在每行末尾使用分号来分隔语句
if [ -v $(git_repo) ]; then \
echo "exists!"; \
else \
echo "not exist!"; \
fi
删除反斜杠和换行符(并替换$(git_repo)
后,shell将看到:
if [ -v some_git_repo ]; then echo "exists!"; else echo "not exist!"; fi
你需要分号。“\”效应是将所有内容放在同一行上
repo:
if [ -v $(git_repo) ]; then \
echo "exists!"; \
else \
echo "not exist!"; \
fi;
请参见
echo
现在以分号结尾。反斜杠不会被make
删除。在你的回音后需要分号,或者使用.ONESHELL
删除所有的反斜杠……在这里,我想我知道足够多的CS,不再犯分号错误了。谢谢