shell - 如何比较Makefile中的两个shell命令输出?

标签 shell if-statement makefile conditional

我的 Makefile是:

.PHONY: check
check:
        ifneq $(shell echo 123), $(shell echo 123)
                $(error Not equal)
        endif

当我运行时,出现错误:
$ make
Makefile:3: *** Not equal.  Stop.

但这应该仅在它们不同时才发生,但事实并非如此。为什么?

最佳答案

ifneq不能缩进。按照您编写的方式,它是通过 shell 命令运行的,这意味着 $(error) make 命令首先评估。

我猜你想要 make check仅在 make check 时才实际运行两个命令被调用,并比较它们的输出。你可以做:

.PHONY: check
check:
    if [ "`echo 123`" != "`echo 123`" ]; then \
        echo "Not equal"; \
        exit 1; \
    fi

关于shell - 如何比较Makefile中的两个shell命令输出?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36346340/

相关文章:

bash - shell 脚本 : How to write a string to file and to stdout on console?

java - ArrayList、for 循环和 if 语句的问题 - 打印列表中每个项目的行

c# - 检查字符串是否有大写、小写和数字

linux - 在 bash 中使用先前命令的输出

linux - Bash 多进程替换重定向顺序

linux - 如何在不使用 shell 脚本中的管道或重定向的情况下将字符串附加到文件的开头或结尾?

objective-c - If-Else 语句被翻转

c - 错误 : expected 'asm' before long

c++ - 如何为 C++ 设置跨平台编译(win7 中的 NetBeans 和 linux 中的 make)

c++ - 使用 makefile (c++) 部分编译和包含 boost