2013-02-25 276 views
6

我在Makefile中有下面的代碼片斷,它總是失敗,除非我刪除下面的sed & grep的引用。如何在makefile shell命令中使用管道?

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 

出了什麼問題?

+1

可能是一個副本http://stackoverflow.com/questions/2382764/escaping-in-makefile – 2013-02-25 16:24:17

+1

只是FYI,sed和grep之一的兩個調用可以組合成一個sed實例:sed -ne '/^\ s * $$ /!{s/^ \ s * //; s/\ s * $$ //; p;}''初始模式只保留空格,空行不被修改或顯示。 (當然,我爲了賺錢而把$加倍了。) – William 2013-02-25 19:27:52

回答

17

一個錯誤來自sed。當你寫:

sed "s/\s*$//" 

化妝擴展變量$/爲空字符串,所以SED缺少一個分隔符。嘗試:

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

使用$"導致了同樣的問題grep。改爲使用grep -v "^\s*$$"