Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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
Makefile VV=$(shell cat foo.txt)导致找不到VV命令_File_Makefile - Fatal编程技术网

Makefile VV=$(shell cat foo.txt)导致找不到VV命令

Makefile VV=$(shell cat foo.txt)导致找不到VV命令,file,makefile,File,Makefile,他, 我希望将文件(包含相对文件路径)的内容读取到一个变量,并在文件中的每一行前面加上路径前缀。然后将所有这些文件复制到一个目录中。 像这样: $(httpd_DIR)/my.tar: $(mypath)/html.txt rm -rf web mkdir -p web VV = $(addprefix $(httpd_DIR)/, $(shell cat $(mypath)/html.txt) ) cp -R $$VV $(httpd_DIR)/web

他,
我希望将文件(包含相对文件路径)的内容读取到一个变量,并在文件中的每一行前面加上路径前缀。然后将所有这些文件复制到一个目录中。 像这样:

$(httpd_DIR)/my.tar: $(mypath)/html.txt
    rm -rf web
    mkdir -p web
    VV = $(addprefix $(httpd_DIR)/, $(shell cat $(mypath)/html.txt) )
    cp -R $$VV $(httpd_DIR)/web
    $(TAR) -C $(httpd_DIR) -cvf $(httpd_DIR)/web.tar web

$(mypath)/html.txt文件包含如下相对文件路径列表:
dir1/file1.html
dir2/file2.html
dir3/file3.html

由于某种原因,我得到了以下错误:
/bin/bash:VV:未找到命令

我没有尝试执行VV,那么为什么het会给我这个错误?
请注意,如果我取消对cp命令的注释,我仍然会得到相同的错误。。。
我正在linux PC上使用GNU make。

这里有几个问题

VV = $(addprefix $(httpd_DIR)/, $(shell cat $(mypath)/html.txt) )
你还没有告诉我们你用的是什么外壳,所以我假设是bash

如果要在bash中分配变量,必须注意空格:
VV=foo
是合法的,并且会按照您的期望执行,但是如果键入
VV=foo
,shell会将第一个单词“VV”解释为一个命令,然后停止。如果键入
VV=foo bar
,shell将
foo
分配给
VV
,然后在命令
bar
处停止。您可以改用
VV=“foo bar”

然后你会遇到另一个问题。每个命令都在其自己的子shell中运行,因此在一个命令中分配的变量无法保存到下一个命令:

VV=foo
echo $$VV # this will echo a blank
必须组合这些命令,如下所示:

VV=foo ; echo $$VV # this will echo foo
或者这个:

VV=foo ; \
  echo $$VV # this will echo foo
(请注意,第一行之前只有一个选项卡。)


通常,在插入真正的命令之前,应该使用您能想到的最简单的命令测试这些构造。这样,捕获这些bug就容易多了。

很好地解释了这一点。另一个问题是命令不创建目标文件。如前所述,这些命令更新web.tar,而不是my.tar。@Idelic:good point。在我引入自动变量(这是这个makefile改进的下一步)之前,我通常不会注意到这样的错误。他,非常感谢你提供的信息,这真的很有帮助!我还将检查自动变量。