Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 351
dhruvbird Avatar asked Feb 25 '13 16:02

dhruvbird


People also ask

What does pipe do in makefile?

In the shell, the pipe symbol causes the stdout from the command on the lefto be hooked up to the stdin of the command on the righ: it's called a pipeline or piping data.

What does pipe symbol mean in makefile?

Order-only prerequisites can be specified by placing a pipe symbol ( | ) in the prerequisites list: any prerequisites to the left of the pipe symbol are normal; any prerequisites to the right are order-only: targets : normal-prerequisites | order-only-prerequisites.


1 Answers

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.

like image 63
William Pursell Avatar answered Sep 24 '22 06:09

William Pursell