简体   繁体   中英

how do I use pipes in a makefile shell command?

I have the following code snippet in a Makefile which always fails unless I remove the references to sed & grep below.

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)

This is the error I get:

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

What could be wrong?

One error is coming from sed . When you write:

sed "s/\s*$//"

make expands the variable $/ to an empty string, so sed is missing a delimiter. Try:

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

Using $" is causing the same problem in grep . Use grep -v "^\\s*$$" instead.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM