【发布时间】:2020-11-11 05:42:39
【问题描述】:
我使用this post 作为如何将参数传递给 make 目标的基础。
我想在这个命令行 arg 上执行字符串比较,使用 this post 作为在 makefile 中进行字符串相等比较的灵感。
更新使用以下建议的答案:
%:
@:
test:
if [ '$(filter-out $@,$(MAKECMDGOALS))' = hi ]; \
echo "WON"; \
else \
echo "LOST"; \
fi
我用 8 个空格代替缩进,没有打印。当我用制表符代替空格时,我收到以下错误:
if [ 'hi' = hi ]; \
echo "WON"; \
else \
echo "LOST"; \
fi
/bin/sh: -c: line 0: syntax error near unexpected token `else'
/bin/sh: -c: line 0: `if [ 'hi' = hi ]; echo "WON"; else echo "LOST"; fi'
make: *** [test] Error 2
最初的尝试:
%:
@:
test:
ifeq ($(filter-out $@,$(MAKECMDGOALS)),hi)
echo "WON"
else
echo "LOST"
endif
但是,当我运行时,make test hi,我得到了
arg="hi"
ifeq (hi,hi)
/bin/sh: -c: line 0: syntax error near unexpected token `hi,hi'
/bin/sh: -c: line 0: `ifeq (hi,hi)'
make: *** [test] Error 2
什么是意外令牌?
【问题讨论】:
标签: bash makefile command-line-arguments