Bash 在makefile中,如何通过shell命令比较同一文件更改前后的时间戳?

Bash 在makefile中,如何通过shell命令比较同一文件更改前后的时间戳?,bash,shell,makefile,timestamp,Bash,Shell,Makefile,Timestamp,首先,这个makefile不起作用 all: A=$(shell stat -c %Y test1);\ echo "A is $$A";\ touch test1;\ B=$(shell stat -c %Y test1);\ echo "B is $$B";\ if (($$A<$$B)); then echo true; fi shell中的输出: $ make A=1513082575;\ echo "A is $A";\ touc

首先,这个makefile不起作用

all:
    A=$(shell stat -c %Y test1);\
    echo "A is $$A";\
    touch test1;\
    B=$(shell stat -c %Y test1);\
    echo "B is $$B";\
    if (($$A<$$B)); then echo true; fi
shell中的输出:

$ make
A=1513082575;\
echo "A is $A";\
touch test1;\
B=1513082575;\
echo "B is $B";\
if (($A<$B)); then echo true; fi
A is 1513082575
B is 1513082575
$ make
A=1513083955;\
echo "A is $A";\
C=;\
B=1513084224;\
echo "B is $B";\
if (($A<$B)); then echo true; fi
A is 1513083955
B is 1513084224
true
$make
A=1513083955\
回声“A是$A”\
C=\
B=1513084224\
回声“B是$B”\

如果(($ASriniV)有效,只需在答案中添加一些$,然后将其放入makefile,谢谢

 all:
    A=$$(stat -c %Y test1);\
    echo "A is $$A";\
   touch test1;\
   B=$$(stat -c %Y test1);\
   echo "B is $$B";\
   if (($$A<$$B)); then echo true; fi
全部:
A=$$(统计数据-c%Y测试1)\
回显“A是$$A”\
触摸测试1\
B=$$(统计数据-c%Y测试1)\
回显“B为$$B”\
如果($$A配方中的
$(shell…
在之前由make展开,则配方实际上被传递到shell。因此,如果名为
test1
的文件存在且其时间戳为
1513082575
,make first将配方展开为:

A=1513082575;\
echo "A is $A";\
touch test1;\
B=1513082575;\
echo "B is $B";\
if (($A<$B)); then echo true; fi
注意1:通过将要为shell保留的
$
加倍(
$$
)进行扩展,以避免扩展

注2:从bash手册的算术评估部分:

在表达式中,shell变量也可以通过名称引用 不使用参数扩展语法


因此,在bash中,
if((a)正确地回答您的问题。感谢SriniV帮助格式化!感谢Renaud的格式化!谢谢!它很有效,解决了我优化旧项目制作的问题。
A=1513082575;\
echo "A is $A";\
touch test1;\
B=1513082575;\
echo "B is $B";\
if (($A<$B)); then echo true; fi
all:
    A=$$(stat -c %Y test1);\
    echo "A is $$A";\
    touch test1;\
    B=$$(stat -c %Y test1);\
    echo "B is $$B";\
    if ((A<B)); then echo true; fi