将文件中的值作为Makefile变量

时间:2015-07-01 21:53:56

标签: bash makefile

我想使用文件中的值传递给Make中的命令。问题上下文是通过一组ID来使用eutils CLI从NCBI获取蛋白质。我想过使用进程替换,但是会传递文件位置,我们需要一个字符串。所以我试图设置本地bash变量并在我的Make步骤中使用它,但我无法让它工作。任何提示都将不胜感激。

zachcp

SHELL := /bin/bash


# efetch with one id
test1.txt:
    efetch -db protein -id 808080249 -format XML >$@

# efetch with two, comma-separated ids 
test2.txt:
    efetch -db protein -id 808080249,806949321  -format XML > $@

# put some ids in a file....
data.txt:
    echo "808080249\n806949321" > $@

# try to call the ids with process substitution.
# doesn't expand before being called so it trips an error...
test3.txt: data.txt
    efetch -db protein -id <(cat $< | xargs printf "%s,") -format XML > $@

# try to set and use a local BASH variable
test4.txt: data.txt
    ids=`cat $< | xargs printf "%s,"`
    efetch -db protein -id $$ids -format XML > $@

1 个答案:

答案 0 :(得分:2)

如果使用$(...)或`...`而不是&lt;(...)

text3.txt可能会有效

RewriteEngine On
RewriteCond %{REQUEST_URI} /\?^
RewriteRule .*$ - [F,L]

text4.txt失败,因为每一行都在不同的shell进程中执行,因此第一行中设置的变量超出了第二行中的范围;如果你把两个陈述都放在同一行上就会有效:

test3.txt: data.txt
    efetch -db protein -id $$(cat $< | xargs printf "%s,") -format XML > $@