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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15071439/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 04:39:54  来源:igfitidea点击:

how do I use pipes in a makefile shell command?

bashshellmakefile

提问by dhruvbird

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

我在 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)

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?

可能有什么问题?

回答by William Pursell

One error is coming from sed. When you write:

一个错误来自sed. 当你写:

sed "s/\s*$//"

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

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

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

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

使用$"是导致同样的问题grep。使用grep -v "^\s*$$"来代替。