makefile中sed命令的字符串参数怎么分行写

时间:2022-05-03 06:12:05
例如

makefile
all:
        sed \
        's/111/222/g; \
        s/333/444/g;' \
        file_001 > file_002

$make
makefile:2: target 'all' does not exist
sed \
's/111/222/g; \
s/333/444/g;' \
file_001 > file_002
sed: -e expression #1, char 27: unterminated address regex
makefile:2: recipe for target 'all' failed
make: *** [all] Error 1

11 个解决方案

#1


后面的几行不要用tab。

#2


引用 1 楼 lovesmiles 的回复:
后面的几行不要用tab。

不行啊,一样

#3


搜“跟我一起写makefile”?

#4


引用 3 楼 zhao4zhong1 的回复:
搜“跟我一起写makefile”?

能告诉我第几章第几节吗?

#5


搜“makefile 续行符”?

#6


引用 5 楼 zhao4zhong1 的回复:
搜“makefile 续行符”?

我的例子里不是用了续行符吗?难道还有别的用法?阁下要是知道的话请直接告诉我。

#7


all:
        sed \
's/111/222/g; \
s/333/444/g;' \
file_001 > file_002

#8


Commands in a Makefile
Home Page (Projects) |  Overview (NMAKE Reference) |  How Do I... Topics (Projects)

A description block or inference rule specifies a block of commands to run if the dependency is out-of-date. NMAKE displays each command before running it, unless /S, .SILENT, !CMDSWITCHES, or @ is used. NMAKE looks for a matching inference rule if a description block is not followed by a commands block.

A commands block contains one or more commands, each on its own line. No blank line can appear between the dependency or rule and the commands block. However, a line containing only spaces or tabs can appear; this line is interpreted as a null command, and no error occurs. Blank lines are permitted between command lines.

A command line begins with one or more spaces or tabs. A backslash ( \ ) followed by a newline character is interpreted as a space in the command; use a backslash at the end of a line to continue a command onto the next line. NMAKE interprets the backslash literally if any other character, including a space or tab, follows the backslash.

A command preceded by a semicolon (;) can appear on a dependency line or inference rule, whether or not a commands block follows:

project.obj : project.c project.h ; cl /c project.c

What do you want to know more about?
Command modifiers

Filename-parts syntax

Inline files in a makefile

#9


引用 7 楼 zhao4zhong1 的回复:
all:
        sed \
's/111/222/g; \
s/333/444/g;' \
file_001 > file_002

这跟我一楼举的反例不是一样吗?

#10


使用-e 选项, 注意2,-4行头的空格
Quote:
  1  sed \
     2   -e 's/xxxx/yyyy/g'\
     3   -e 's/yyyy/xxxx/g'\
     4   demo.c
     [/quote】

#11


引用 10 楼 mujiok2003 的回复:
使用-e 选项, 注意2,-4行头的空格
Quote:
  1  sed \
     2   -e 's/xxxx/yyyy/g'\
     3   -e 's/yyyy/xxxx/g'\
     4   demo.c
     [/quote】

这个对了,谢谢

#1


后面的几行不要用tab。

#2


引用 1 楼 lovesmiles 的回复:
后面的几行不要用tab。

不行啊,一样

#3


搜“跟我一起写makefile”?

#4


引用 3 楼 zhao4zhong1 的回复:
搜“跟我一起写makefile”?

能告诉我第几章第几节吗?

#5


搜“makefile 续行符”?

#6


引用 5 楼 zhao4zhong1 的回复:
搜“makefile 续行符”?

我的例子里不是用了续行符吗?难道还有别的用法?阁下要是知道的话请直接告诉我。

#7


all:
        sed \
's/111/222/g; \
s/333/444/g;' \
file_001 > file_002

#8


Commands in a Makefile
Home Page (Projects) |  Overview (NMAKE Reference) |  How Do I... Topics (Projects)

A description block or inference rule specifies a block of commands to run if the dependency is out-of-date. NMAKE displays each command before running it, unless /S, .SILENT, !CMDSWITCHES, or @ is used. NMAKE looks for a matching inference rule if a description block is not followed by a commands block.

A commands block contains one or more commands, each on its own line. No blank line can appear between the dependency or rule and the commands block. However, a line containing only spaces or tabs can appear; this line is interpreted as a null command, and no error occurs. Blank lines are permitted between command lines.

A command line begins with one or more spaces or tabs. A backslash ( \ ) followed by a newline character is interpreted as a space in the command; use a backslash at the end of a line to continue a command onto the next line. NMAKE interprets the backslash literally if any other character, including a space or tab, follows the backslash.

A command preceded by a semicolon (;) can appear on a dependency line or inference rule, whether or not a commands block follows:

project.obj : project.c project.h ; cl /c project.c

What do you want to know more about?
Command modifiers

Filename-parts syntax

Inline files in a makefile

#9


引用 7 楼 zhao4zhong1 的回复:
all:
        sed \
's/111/222/g; \
s/333/444/g;' \
file_001 > file_002

这跟我一楼举的反例不是一样吗?

#10


使用-e 选项, 注意2,-4行头的空格
Quote:
  1  sed \
     2   -e 's/xxxx/yyyy/g'\
     3   -e 's/yyyy/xxxx/g'\
     4   demo.c
     [/quote】

#11


引用 10 楼 mujiok2003 的回复:
使用-e 选项, 注意2,-4行头的空格
Quote:
  1  sed \
     2   -e 's/xxxx/yyyy/g'\
     3   -e 's/yyyy/xxxx/g'\
     4   demo.c
     [/quote】

这个对了,谢谢