【问题标题】:Bash 'until' loop syntax error in MakefileMakefile中的Bash'直到'循环语法错误
【发布时间】:2020-05-14 00:41:47
【问题描述】:

在执行 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 `;'

【问题讨论】:

标签: bash shell makefile syntax-error gnu-make


【解决方案1】:

在 '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

【讨论】:

  • 这最终成为了完美的解决方案。
猜你喜欢
  • 2015-04-17
  • 1970-01-01
  • 2022-06-30
  • 2017-06-05
  • 2017-04-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多