通配符变量到逗号连接的字符串
wildcard to variable to comma-joined string
我正在使用生成文件来控制软件管道。我需要将逗号分隔的目录列表作为参数传递,也就是
--dirs output/a,output/b,output/c
未知。我想做类似的事情:
dirs = output/*
dirString = ",".join(dirs)
这可能吗?
A shell 用于执行命令,因此您可以调用任何可用的实用程序来构建命令行。例如,在类 Unix 系统上:
output/result: output/*
echo $+ | sed 's/ /,/g' | xargs command > $@
我发现在 make 中做这些事情通常更好。 Noddy 解析使得 ,
和 </code> 的处理比它应该的更棘手:-(</p>
<pre><code>space :=
space += # $space is a space
comma := ,
comma-separate = $(subst ${space},${comma},$(strip ))
list := a b other stuff # trailing space
$(error [$(call comma-separate,${list})])
接受的答案中的配方显然是 command $(call comma-separate,$+)
我正在使用生成文件来控制软件管道。我需要将逗号分隔的目录列表作为参数传递,也就是
--dirs output/a,output/b,output/c
未知。我想做类似的事情:
dirs = output/*
dirString = ",".join(dirs)
这可能吗?
A shell 用于执行命令,因此您可以调用任何可用的实用程序来构建命令行。例如,在类 Unix 系统上:
output/result: output/*
echo $+ | sed 's/ /,/g' | xargs command > $@
我发现在 make 中做这些事情通常更好。 Noddy 解析使得 ,
和 </code> 的处理比它应该的更棘手:-(</p>
<pre><code>space :=
space += # $space is a space
comma := ,
comma-separate = $(subst ${space},${comma},$(strip ))
list := a b other stuff # trailing space
$(error [$(call comma-separate,${list})])
接受的答案中的配方显然是 command $(call comma-separate,$+)