bash -/bin/sh : 1: Bad substitution Makefile

标签 bash shell docker makefile

<分区>

我已经编写了一个脚本来查找所有正在运行的具有特定名称的 docker 容器,当我直接将它输入我的终端时它可以工作但是一旦我将它放入 Makefile 它就会抛出错误

/bin/sh: 1: Bad substitution

这是makefile中的脚本:

remote: FORCE
   docker ps -q --filter name=$$(tmp=$${PWD##*/} && printf "%s_workspace" "$${tmp//./}")

为了阐明 name= 之后的 block 在做什么,它试图获取当前文件夹名称并删除所有 .'s 并将其附加到我的容器名称,即工作空间。

最佳答案

/bin/sh 不支持您使用的替换运算符。您需要告诉 make 改用 bash:

SHELL := /bin/bash

如果你想让你的食谱与 POSIX 兼容,请改用 tr:

remote: FORCE
        docker ps -q --filter name=$$(printf '%s_workspace' "$${PWD##*/}" | tr -d .)

如果你正在使用 GNU make,你可能想使用

remote: FORCE
        docker ps -q --filter name=$(subst .,,$(notdir $(PWD)))_workspace

而不是让 make 处理所有字符串本身。

关于bash -/bin/sh : 1: Bad substitution Makefile,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50649104/

相关文章:

linux - 尝试在文件名中查找单词的 shell 脚本中出现错误

security - Docker只读套接字卷

php - docker-compose 覆盖容器中的目录

html - 如何在 bash 中从 HTML 文档中提取特定文本?

string - 在 bash 中返回破折号之前的子字符串,后跟数字

linux - bash 问题 : AWK

linux - 如何使此 "action-packed, random data"在终端中回显?

ubuntu - Dockerfile 中的 neo4j - "service neo4j-service start"未分离

bash - -bash : ls: command not found

bash - 测试是否有任何文件超过 7 天