I am running the following inside the makefile:-
@START=$(shell date +%s) && \
echo $${START} &&\
sleep 10s && \
END=$(shell date +%s) && \
echo "$${END} $${START}" &&\
DIFF_SUB=$$(($$END - $$START)) && \
echo IT TOOK $${DIFF_SUB} SECONDS
and it outputs to the following:-
1309950228
1309950228 1309950228
IT TOOK 0 SECONDS
The reason you are getting the same result for each
$(shell date +%s)is that each is being executed and substituted at the same time – that is whenmakeis running the command.After
makedoes its substitutions, this is the command the shell sees:If you want the
datecommand to be run twice with a 10 second time difference between them, you will need the shell to perform the command substitution, notmake:Note the double
$$and the removal of theshellmakecommand.