Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/143.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
Web 将html文件从源目录复制到生成目录_Web_Gnu Make_Web Frontend - Fatal编程技术网

Web 将html文件从源目录复制到生成目录

Web 将html文件从源目录复制到生成目录,web,gnu-make,web-frontend,Web,Gnu Make,Web Frontend,我正在为一个网站写一个makefile 我有一个名为src/和build/ 基本上,我想要这样的文件: src/index.html src/blog/title1/index.html src/blog/title2/index.html build/index.html build/blog/title1/index.html build/blog/title2/index.html #! /bin/bash # get htm files find . -name '*html' &

我正在为一个网站写一个makefile

我有一个名为
src/
build/

基本上,我想要这样的文件:

src/index.html
src/blog/title1/index.html
src/blog/title2/index.html
build/index.html
build/blog/title1/index.html
build/blog/title2/index.html
#! /bin/bash

# get htm files
find . -name '*html' > files

# manipulate file location
sed 's/src/build/' files | paste files - > mapping

# handle spaces in the file names
sed 's/ /\\ /' mapping > files

# output mapping to be sure.
cat files
echo "Apply mapping?[Y/n]"
read reply
[[ $reply =~ [Yy].* ]] || exit 1
# copy files from column one to column two
awk '{ system("cp "$1" "$2)}' files

exit 0
然后将它们复制到
build/
目录,如下所示:

src/index.html
src/blog/title1/index.html
src/blog/title2/index.html
build/index.html
build/blog/title1/index.html
build/blog/title2/index.html
#! /bin/bash

# get htm files
find . -name '*html' > files

# manipulate file location
sed 's/src/build/' files | paste files - > mapping

# handle spaces in the file names
sed 's/ /\\ /' mapping > files

# output mapping to be sure.
cat files
echo "Apply mapping?[Y/n]"
read reply
[[ $reply =~ [Yy].* ]] || exit 1
# copy files from column one to column two
awk '{ system("cp "$1" "$2)}' files

exit 0
我尝试编写规则,但我不确定如何调试:

src_html := src/**/*.html
build_html := $(shell find src -name '*.html' | sed 's/src/build/')

$(src_html): $(build_html)
    @cp $< $@
src\u html:=src/***.html
build_html:=$(shell find src-name'*.html'| sed's/src/build/)
$(src\u html):$(build\u html)
@cp$<$@

尝试以下方法:

src/index.html
src/blog/title1/index.html
src/blog/title2/index.html
build/index.html
build/blog/title1/index.html
build/blog/title2/index.html
#! /bin/bash

# get htm files
find . -name '*html' > files

# manipulate file location
sed 's/src/build/' files | paste files - > mapping

# handle spaces in the file names
sed 's/ /\\ /' mapping > files

# output mapping to be sure.
cat files
echo "Apply mapping?[Y/n]"
read reply
[[ $reply =~ [Yy].* ]] || exit 1
# copy files from column one to column two
awk '{ system("cp "$1" "$2)}' files

exit 0
编辑

不,等等,我有一个班轮:

$ find -name '*html' -exec bash -c 'file=$(echo {}); file=$(echo $file | sed "s:\/:\\\/:g"); cp "{}" $(echo ${file/src/build} | sed "s:\\\/:\/:g")' \;

试着这样做:

src/index.html
src/blog/title1/index.html
src/blog/title2/index.html
build/index.html
build/blog/title1/index.html
build/blog/title2/index.html
#! /bin/bash

# get htm files
find . -name '*html' > files

# manipulate file location
sed 's/src/build/' files | paste files - > mapping

# handle spaces in the file names
sed 's/ /\\ /' mapping > files

# output mapping to be sure.
cat files
echo "Apply mapping?[Y/n]"
read reply
[[ $reply =~ [Yy].* ]] || exit 1
# copy files from column one to column two
awk '{ system("cp "$1" "$2)}' files

exit 0
编辑

不,等等,我有一个班轮:

$ find -name '*html' -exec bash -c 'file=$(echo {}); file=$(echo $file | sed "s:\/:\\\/:g"); cp "{}" $(echo ${file/src/build} | sed "s:\\\/:\/:g")' \;

如果安装了rsync,您可以使用它

default:
        rsync -r --include '*/' --include='*.html' --exclude='*' src/ build/

如果安装了rsync,您可以使用它

default:
        rsync -r --include '*/' --include='*.html' --exclude='*' src/ build/
出于完整性考虑,make可以使用静态模式规则处理此问题:

src := src/index.html src/blog/title1/index.html src/blog/title2/index.html
# or src := $(shell find …) etc., but hopefully the makefile already has a list

dst := $(patsubst src/%,build/%,${src})
${dst}: build/%: src/% ; cp $< $@

.PHONY: all
all: ${dst}
src:=src/index.html src/blog/title1/index.html src/blog/title2/index.html
#或者src:=$(shell find…)等等,但希望makefile已经有了一个列表
dst:=$(patsubst src/%,build/%,${src})
${dst}:build/%:src/%;cp$<$@
冒牌货:全部
全部:${dst}
这也是安全的,而且不会复制未更新的文件。

为了完整起见,make可以使用静态模式规则处理此问题:

src := src/index.html src/blog/title1/index.html src/blog/title2/index.html
# or src := $(shell find …) etc., but hopefully the makefile already has a list

dst := $(patsubst src/%,build/%,${src})
${dst}: build/%: src/% ; cp $< $@

.PHONY: all
all: ${dst}
src:=src/index.html src/blog/title1/index.html src/blog/title2/index.html
#或者src:=$(shell find…)等等,但希望makefile已经有了一个列表
dst:=$(patsubst src/%,build/%,${src})
${dst}:build/%:src/%;cp$<$@
冒牌货:全部
全部:${dst}

这是
-j
也很安全,而且不会复制尚未更新的文件。

首先,在进行通配符匹配时,应该使用1*而不是2。首先,在进行通配符匹配时,应该使用1*而不是2。该死的,这是一个很好的解决方案,我想我必须执行
man rsync
+1为优雅的脚本!该死的,这是一个很好的解决方案,我想我得做一个
manrsync
+1为优雅的脚本!只需使用真正有用的mmv命令
mmv-vcd'src/;*。html''build/#1#2.html'
非常感谢您共享该命令,我一定会研究它!只需使用真正有用的mmv命令
mmv-vcd'src/;*。html''build/#1#2.html'
非常感谢您共享该命令,我一定会研究它!