gpt4 book ai didi

linux - 如何计算 Makefile 中的范围

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:06:10 24 4
gpt4 key购买 nike

这是我的 Makefile 和输出,如何打印像 [1-5, 7, 9-10] 这样的范围?

$ ls /tmp/foo
foo10.txt foo1.txt foo2.txt foo3.txt foo4.txt foo5.txt foo7.txt foo9.txt

$ cat Makefile
DIR1 := /tmp/foo/
COMMA :=,
EMPTY :=
SPACE := $(EMPTY) $(EMPTY)
VERSIONS := $(subst $(SPACE),$(COMMA),$(patsubst foo%,%,$(basename $(notdir $(wildcard $(DIR1)/foo*.txt)))))
all:
$(info versions is [${VERSIONS}])

$ make
versions is [10,1,2,3,4,5,7,9]

最佳答案

有几种方法:

  1. 如果您知道最大可能值:首先,添加 SHELL=bash 以便大括号扩展有效。然后使用 $(shell {1..10}) 之类的东西,并将结果传递给 $(wildcard) 以排除不存在的文件。
  2. 通过 sort -n 管道,再次在 $(shell) 中。
  3. 0填充左边的数字,然后正常排序。

关于linux - 如何计算 Makefile 中的范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46288292/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com