sed未知选项的错误

时间:2015-12-14 08:13:19

标签: linux bash sed makefile

我有一个Makefile,它有一行:

sed -i -e 's/\(^COPTS = \)/\1$(CFLAGS) /' $(DIR)/Makefile

替换值后,它变为:

sed -i -e 's/\(^COPTS = \)/\1"-I/home/jagadeesh/Smoothwall/bcutm/distrib/tools//powerpc-linux/include -I/home/jagadeesh/Smoothwall/bcutm/distrib/usr/include/ncurses -I/home/jagadeesh/Smoothwall/bcutm/distrib/usr/include" /' net-tools-1.60/Makefile

当make运行时,会出现以下错误:

sed: -e expression #1, char 23: unknown option to `s'

将运行此sed命令的net-tool-1.60 / Makefile包含以下相关行:

COPTS = -D_GNU_SOURCE -O2 -Wall -g # -I/usr/inet6/include
CFLAGS  = $(COPTS) -I. -idirafter ./include/ -I$(NET_LIB_PATH)
MDEFINES = COPTS='$(COPTS)' LOPTS='$(LOPTS)' TOPDIR='$(TOPDIR)'

该命令做什么,Makefile的哪一行,为什么出现错误,我没有修改除我自定义的CFLAGS和LDFLAGS之外的任何内容。

1 个答案:

答案 0 :(得分:2)

由于替换部件包含分隔符/,因此命令失败。我建议使用不同的分隔符,让我们说~

sed -i -e 's~\(^COPTS = \)~\1$(CFLAGS) ~' $(DIR)/Makefile