首页 > 解决方案 > Makefile中的Bash'直到'循环语法错误

问题描述

在执行 load_db 脚本之前尝试通过它的 HTTP 状态检查数据库是否准备好:

db:
    ## Startup database container, takes about 30 seconds to be available on port 7474

load_db: db
    ## Check status and break loop if successful
    until $(curl --output /dev/null --silent --head --fail http://localhost:7474) ; do \
        printf '.' ; \
        sleep 5 ; \
    done
    ## load database

每次我运行时,make load_db我都会收到错误消息:
/bin/bash: -c: line 0: syntax error near unexpected token `;'

标签: bashshellmakefilesyntax-errorgnu-make

解决方案


在 'Makefile' 中,'$(something)' 有特殊的含义——它会导致 Make 的变量 something(或同名的环境变量)。您想转义“$”,以便将其传递给外壳。通常,只需使用 '$$' 就可以了。

load_db: db
    ## Check status and break loop if successful
    until $$(curl --output /dev/null --silent --head --fail http://localhost:7474) ; do \
        printf '.' ; \
        sleep 5 ; \
    done

推荐阅读