Bash 如何在makefile shell命令中使用管道?

Bash 如何在makefile shell命令中使用管道?,bash,shell,makefile,Bash,Shell,Makefile,我在Makefile中有下面的代码片段,除非我删除下面对sed&grep的引用,否则它总是失败的 TAB=$(shell printf "\t") all: abstract.tsv $(shell cut -d "${TAB}" -f 3 abstract.tsv | sed "s/^\s*//" | \ sed "s/\s*$//" | grep -v "^\s*$" | sort -f -S 300M | \ uniq > referenc

我在Makefile中有下面的代码片段,除非我删除下面对sed&grep的引用,否则它总是失败的

TAB=$(shell printf "\t")
all: abstract.tsv
      $(shell cut -d "${TAB}" -f 3 abstract.tsv | sed "s/^\s*//" | \
        sed "s/\s*$//" | grep -v "^\s*$" | sort -f -S 300M | \
        uniq > referenced_images.sorted.tsv)
这是我得到的错误:

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

有什么问题吗?

一个错误来自
sed
。当你写作时:

sed "s/\s*$//"
make将变量
$/
扩展为空字符串,因此sed缺少分隔符。尝试:

sed "s/\s*$$//"

使用
$”
会在
grep
中引起同样的问题。请改用
grep-v“^\s*$$”

可能是仅供参考的副本,sed的两个调用和grep的一个调用可以组合到一个sed实例中:
sed-ne'/^\s*$$/!{s/^\s*//;s/\s*$$$/;p;}“
初始模式仅保留空间,不允许修改或显示空行。(当然,为了make的利益,我将$s翻了一番。)