Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/326.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
Bash 如何循环将groff文档编译到特定文件夹中_Bash_Shell_Scripting_Pdf Generation_Groff - Fatal编程技术网

Bash 如何循环将groff文档编译到特定文件夹中

Bash 如何循环将groff文档编译到特定文件夹中,bash,shell,scripting,pdf-generation,groff,Bash,Shell,Scripting,Pdf Generation,Groff,我有几个.ms文档分散在不同的文件夹中,我想制作一个脚本,编译每个.ms文档并在特定文件夹中输出相应的.pdf文件 文件夹结构如下所示: /home/user/foo/folder1/file1.ms /home/user/foo/folder2/file2.ms /home/user/foo/folder3/file3.ms ... 以下是我迄今为止所做的工作: #!/bin/bash folder="/home/user/foo/" file=$(du -a "

我有几个.ms文档分散在不同的文件夹中,我想制作一个脚本,编译每个.ms文档并在特定文件夹中输出相应的.pdf文件

文件夹结构如下所示:

/home/user/foo/folder1/file1.ms
/home/user/foo/folder2/file2.ms
/home/user/foo/folder3/file3.ms
...
以下是我迄今为止所做的工作:

#!/bin/bash
folder="/home/user/foo/"
file=$(du -a "$folder" | grep ".ms" | cut -f2- | sort)
但是,我不知道如何使循环将输出的每一行转换为相应的.pdf文件,例如:

/home/user/foo/bar/file1.pdf
/home/user/foo/bar/file2.pdf
/home/user/foo/bar/file3.pdf
...
我用于将.ms编译为.pdf的groff命令是:

groff -k -T pdf -ms file.ms > file.pdf
编辑 感谢您的回答,我已将脚本更新为:

#!/bin/bash
input="/home/user/foo/"
output="/home/user/foo/bar"
find $input -name '*.ms' -execdir sh -c 'groff -k -T pdf -ms {} > $output$(basename {} .ms).pdf' \;

但是,这只编译第一个文档,不将其放在“output”目录中,而是放在与.ms文件相同的目录中,我得到了“1:Syntax error:”)“unexpected”。

表面上,需要两个步骤:

  • 查找所有“.ms”文件(使用查找…)
  • 将每个文件转换为PDF(在查找中使用-execdir)
folder=...
find $folder -name '*.ms' -execdir sh -c 'groff -k -t -pdf -ms {} > $(basename {} .ms).pdf' \;
#!/bin/bash
input="/home/matthieu/Documents/Philosophie/L1"
output="/home/matthieu/Documents/Philosophie/L1/S1/Cours"
find "$input" -name '*.ms' -execdir sh -c 'groff -k -T pdf -ms "$1" > "$2/${1%.ms}.pdf"' sh {} "$output" \;