带有 sed throwing *** 目标模式的 Makefile 不包含“%”。停止
Makefile with sed throwing *** target pattern contains no '%'. Stop
我有一个 Makefile,我需要在其中将图像名称传递给另一个脚本,但问题是,图像名称在其行中有 : 和 - 例如:image.name-v1:latest。根据 google make file having : in variable 会导致问题。如何在 Makefile 中解决此问题。下面是我正在尝试的示例代码,其中 IMAGE 具有 image.name-v1:latest
IMAGE2 ?= ''
.PHONY: image
image:
IMAGE2 := $(subst :,\:,$(IMAGE_R)) ## IMAGE_R is a run time variable for make target
rr/image.sh $(IMAGE2)
错误:
IMAGE2 := docker-rs\:latest ## Test Image using Image Reference
/bin/sh: 1: IMAGE2: not found
Makefile:75: recipe for target 'image' failed
make: *** [image] Error 127
SHELL 脚本:image.sh
#!/bin/bash
set -ex
IMAGE=""
echo "Image: $IMAGE"
您可以尝试像这样转义冒号:
# Mock IMAGE with colon in name
IMAGE := test:123
# Create new variable adding an escapeing slash
IMAGE2 := $(subst :,\:,$(IMAGE))
# Use IMAGE2 from here on
$(info IMAGE $(IMAGE))
$(info IMAGE2 $(IMAGE2))
.PHONY: xyz-pp
xyz-pp: $(IMAGE2)
.PHONY: $(IMAGE2)
$(IMAGE2):
@echo "1234" > $(IMAGE2)
@ls
@rr/image.sh $(IMAGE2)
我在子文件夹 rr
中添加了一个脚本:
echo "------------- SCRIPT ----------"
echo PARAM:
echo $(find -name "")
echo "------------- SCRIPT ----------"
输出:
> make
IMAGE test:123
IMAGE2 test\:123
makefile rr test:123
------------- SCRIPT ----------
PARAM: test:123
./test:123
------------- SCRIPT ----------
所以这里我只是将“:”替换为“:”到一个变量 IMAGE2 中,然后使用它。
注意:我通过回显你的命令(因为我没有那个文件)并触摸 IMAGE2 来创建文件来测试这个
我有一个 Makefile,我需要在其中将图像名称传递给另一个脚本,但问题是,图像名称在其行中有 : 和 - 例如:image.name-v1:latest。根据 google make file having : in variable 会导致问题。如何在 Makefile 中解决此问题。下面是我正在尝试的示例代码,其中 IMAGE 具有 image.name-v1:latest
IMAGE2 ?= ''
.PHONY: image
image:
IMAGE2 := $(subst :,\:,$(IMAGE_R)) ## IMAGE_R is a run time variable for make target
rr/image.sh $(IMAGE2)
错误:
IMAGE2 := docker-rs\:latest ## Test Image using Image Reference
/bin/sh: 1: IMAGE2: not found
Makefile:75: recipe for target 'image' failed
make: *** [image] Error 127
SHELL 脚本:image.sh
#!/bin/bash
set -ex
IMAGE=""
echo "Image: $IMAGE"
您可以尝试像这样转义冒号:
# Mock IMAGE with colon in name
IMAGE := test:123
# Create new variable adding an escapeing slash
IMAGE2 := $(subst :,\:,$(IMAGE))
# Use IMAGE2 from here on
$(info IMAGE $(IMAGE))
$(info IMAGE2 $(IMAGE2))
.PHONY: xyz-pp
xyz-pp: $(IMAGE2)
.PHONY: $(IMAGE2)
$(IMAGE2):
@echo "1234" > $(IMAGE2)
@ls
@rr/image.sh $(IMAGE2)
我在子文件夹 rr
中添加了一个脚本:
echo "------------- SCRIPT ----------"
echo PARAM:
echo $(find -name "")
echo "------------- SCRIPT ----------"
输出:
> make
IMAGE test:123
IMAGE2 test\:123
makefile rr test:123
------------- SCRIPT ----------
PARAM: test:123
./test:123
------------- SCRIPT ----------
所以这里我只是将“:”替换为“:”到一个变量 IMAGE2 中,然后使用它。
注意:我通过回显你的命令(因为我没有那个文件)并触摸 IMAGE2 来创建文件来测试这个