在Windows上使用Pandoc连接多个Markdown文件 [英] Concatenate multiple Markdown files using Pandoc on Windows

查看:103
本文介绍了在Windows上使用Pandoc连接多个Markdown文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在一个文件夹中有几个Markdown(.code )文件,我想将它们连接起来并使用Pandoc获得最终的Markdown文件.我写了一个这样的bash文件:

I have several Markdown (.md) files in a folder and I want to concatenate them and get a final Markdown file using Pandoc. I wrote a bash file like this:

#!/bin/bash 
pandoc *.md > final.md

但是当我双击它时出现以下错误:

But I am getting the following error when I double-click on it:

pandoc:* .md:openBinaryFile:无效参数(无效参数)

pandoc: *.md: openBinaryFile: invalid argument (Invalid argument)

final.md 文件为空.

如果我尝试这样做:

pandoc file1.md file2.md .... final.md 

我得到了我期望的结果:一个包含所有其他Markdown文件内容的 final.md 文件.

I am getting the results I expect: a final.md file with the contents of all the other Markdown files.

在macOS上运行正常.为什么这在Windows上不起作用?

On macOS it works fine. Why doesn't this work on Windows?

推荐答案

在类Unix的shell(例如bash,为其编写脚本)上,全局扩展(例如,将 *.md 转换为 file1.md file2.md file3.md )由执行外壳,而不是您正在运行的应用程序.您的应用程序将看到文件的最终列表,而不是通配符.

On Unix-like shells (like bash, for which your script is written) glob expansion (e.g. turning *.md into file1.md file2.md file3.md) is performed by the shell, not the application you're running. Your application sees the final list of files, not the wildcard.

但是, cmd.exe 中的全局扩展是由应用程序执行的:

However, glob expansion in cmd.exe is performed by the application:

Windows 命令解释器

The Windows command interpreter cmd.exe relies on a runtime function in applications to perform globbing.

结果是,当Pandoc希望看到诸如 file1.md file2.md file3.md 之类的文件列表时,正在传递原义的 *.md .它不知道如何扩展glob本身,并尝试打开名称为 *.md 的文件.

As a result, Pandoc is being passed a literal *.md when it expects to see a list of files like file1.md file2.md file3.md. It doesn't know how to expand the glob itself and tries to open a file whose name is *.md.

您应该能够在像Cygwin或跳转一些箍来编写一个批处理文件,该文件可以扩展glob并将文件名传递给Pandoc.

You should be able to run your bash script in a unix-like shell like Cygwin or bash on Windows. It may also work on PowerShell, though I don't have a machine handy to test. As a last resort you could jump through some hoops to write a batch file that expands the glob and passes file names to Pandoc.

这篇关于在Windows上使用Pandoc连接多个Markdown文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆