Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用';subst';在多行makefile bash脚本中?_Bash_Shell_Makefile - Fatal编程技术网

使用';subst';在多行makefile bash脚本中?

使用';subst';在多行makefile bash脚本中?,bash,shell,makefile,Bash,Shell,Makefile,我读了这个问题:,但我仍然无法使我的shell脚本正常工作 我有一个makefile,其中有一行内容: #@public_detailed@|test|create |语法:commoncmdsyntax test_create test_name= 目标运行多行bash脚本,其中commoncmdsyntax必须替换为包含单词和空格的字符串 在脚本中,我使用cut将字符串Syntax:commoncmdsyntax test\u create test\u name=分配给变量desc 问题在

我读了这个问题:,但我仍然无法使我的shell脚本正常工作

我有一个makefile,其中有一行内容:

#@public_detailed@|test|create |语法:commoncmdsyntax test_create test_name=

目标运行多行bash脚本,其中
commoncmdsyntax
必须替换为包含单词和空格的字符串

在脚本中,我使用cut将字符串
Syntax:commoncmdsyntax test\u create test\u name=
分配给变量
desc

问题在于
$(subst commoncmdsyntax,new text,$$desc)
并没有将
commoncmdsyntax
替换为
new text


我试图用一个单词替换它,比如
XX
,但它也不起作用。

函数(如
$(subst commoncmdsyntax,new text,$$desc)
)是一个Make函数,因此Make将在运行任何规则之前执行替换,因此在脚本为
desc
赋值之前执行替换。因此,即使二次扩张按照您似乎认为的方式进行,这种方法仍然会失败

如果要在shell脚本(在配方中)生成的内容中执行替换,明智的方法是在配方中执行替换:

echo $dest | sed 's/commoncmdsyntax/new text/'

如果您提供问题的详细信息,我们可以为您提供更详细的解决方案。

请编辑您的问题,以显示
make-v
的输出。祝你好运。
make-v
报告我正在使用的
GNU make 3.81
二次扩展在make 3.81中可用。该示例行是一条注释。二次扩展仅在目标先决条件下发生。你能在这里给我们看看你的makefile的片段吗?因为我很难理解你在做什么,你在用什么。这听起来像是你试图跨越make/shell的界限,并且没有正确理解二次扩展。正如我在下面的Beta版中评论的答案,我使用了
sed
。谢谢你的时间!我放弃了使用
subst
,而是以这种方式准确地使用了
sed
。谢谢