首页 > 解决方案 > Makefile括号处理问题

问题描述

试图弄清楚如何处理 Makefile 中的“)”,但找不到任何示例

这是我必须处理的问题的一个简单示例,即在降价文件中提取用户列表

如果我在 bash 中这样做

echo '[ted toe](https://somewhere/users/tedtoe)' | awk -F '[/)]' '{print $5}'

我按预期得到了 tedtoe

但是当我尝试使用这个 Makefile

SHELL=/bin/bash

OWNERS := $(shell echo '[ted toe](https://somewhere/users/tedtoe)' | awk -F '[/)]' '{print $$5}')

owners:
        @echo "The owners are ${OWNERS}"

我得到以下输出

/bin/bash: -c: line 0: unexpected EOF while looking for matching `''
/bin/bash: -c: line 1: syntax error: unexpected end of file
The owners are

当我尝试使用“)”作为字段分隔符时,它会失败我也尝试过管道和使用tr -d ')',但这也失败了

任何人都必须处理 make 文件中的括号问题?

标签: bashmakefile

解决方案


在解析您的OWNERS定义时,make 解释右括号并将右括号'[/)]'视为关闭$(shell ...). 改用 make 变量:

CP := )
OWNERS := $(shell echo '[ted toe](https://somewhere/users/tedtoe)' | awk -F '[/$(CP)]' '{print $$5}')

推荐阅读