我在 Makefile 中有以下代码:
NODES = celery1 celery2 celery3 priority export
get-status = /bin/bash -c "ps -p `/bin/bash -c '[ -a log/$(1).pid ] && cat log/$(1).pid || echo 1'` -o command= | grep $(1) > /dev/null && echo \"[$(1)] Appears to be running\" || eval 'echo \"[$(1)] Not running\" && exit 1'"
celery-status:
for n in ${NODES}; do $(call get-status,$$n); done
我无法让它工作。当我这样做时:
get-status = /bin/bash -c "ps -p `/bin/bash -c '[ -a log/$(1).pid ] && cat log/$(1).pid || echo $(1)'` -o command= | grep $(1) > /dev/null && echo \"[$(1)] Appears to be running\" || eval 'echo \"[$(1)] Not running\" && exit 1'" 1 displaying the argument instead of 1
celery-status:
for n in ${NODES}; do echo $(call get-status,$$n); done # echo the statements
这是输出:
/bin/bash -c ps -p -o command= | grep celery1 > /dev/null && echo "[celery1] Appears to be running" || eval 'echo "[celery1] Not running" && exit 1'
/bin/bash -c ps -p -o command= | grep celery2 > /dev/null && echo "[celery2] Appears to be running" || eval 'echo "[celery2] Not running" && exit 1'
/bin/bash -c ps -p -o command= | grep celery3 > /dev/null && echo "[celery3] Appears to be running" || eval 'echo "[celery3] Not running" && exit 1'
/bin/bash -c ps -p -o command= | grep priority > /dev/null && echo "[priority] Appears to be running" || eval 'echo "[priority] Not running" && exit 1'
/bin/bash -c ps -p -o command= | grep export > /dev/null && echo "[export] Appears to be running" || eval 'echo "[export] Not running" && exit 1'
看起来$(1)
不起作用,也许我没有正确转义。
我在这里有点绝望:/