首页 > 解决方案 > 使用 gnu make 提取 6 个字符的子字符串

问题描述

我使用以下方法提取了一个 git 哈希字符串:

git describe --always --abbrev=6

即我想获得 6 个字符。问题是如果 6 个字符的标签不是唯一的,git 似乎给了我 7 个字符。所以我想使用标准 make / bash 命令(如 sed)提取前 6 个字符。make 本身似乎不支持子字符串。

目前我的 make 脚本包含以下内容:

foo:=$(lastword $(subst M,,$(subst :, ,$(shell git describe --always --abbrev=6))))

这可能导致 foo=e94181c 但我喜欢它只是 e94181 以适应 24 位内存区域。

标签: gitmakefilesubstring

解决方案


我可能会这样做:

foo := $(shell git describe --always --abbrev=6 | cut -c 1-6)

推荐阅读