使用脚本将多个目录中的多个 Markdown 文件转换为 HTML
我目前有一个很大的目录,其中充满了许多子目录,每个子目录中都有相同名称的 markdown 文件:
/big-directory/sub-directory-name-1/sub-directory-name-1.md
/big-directory/sub-directory-name-2/sub-directory-name-2.md
/big-directory/sub-directory-name-3/sub-directory-name-3.md
我想以这样的结果结束:
/big-directory/sub-directory-name-1/sub-directory-name-1.md
/big-directory/sub-directory-name-1/index.html
/big-directory/sub-directory-name-2/sub-directory-name-2.md
/big-directory/sub-directory-name-1/index.html
/big-directory/sub-directory-name-3/sub-directory-name-3.md
/big-directory/sub-directory-name-1/index.html
我正在尝试在 OS X 上编写一个 shell 脚本,该脚本将在每个文件上运行 multimarkdown,但我很难弄清楚如何使循环在子目录上运行,而不手动将它们全部放入脚本中。预先感谢您的任何帮助。
I currently have a big big directory filled with many sub-directories with identically named markdown files in each:
/big-directory/sub-directory-name-1/sub-directory-name-1.md
/big-directory/sub-directory-name-2/sub-directory-name-2.md
/big-directory/sub-directory-name-3/sub-directory-name-3.md
I would like to end up with this:
/big-directory/sub-directory-name-1/sub-directory-name-1.md
/big-directory/sub-directory-name-1/index.html
/big-directory/sub-directory-name-2/sub-directory-name-2.md
/big-directory/sub-directory-name-1/index.html
/big-directory/sub-directory-name-3/sub-directory-name-3.md
/big-directory/sub-directory-name-1/index.html
I'm trying to write a shell script on OS X that will run multimarkdown on each file, but I'm having difficulty figuring out how to make the loop run over the subdirectories without manually putting them all into the script. Thanks in advance for any help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
要获取 /big-directory 下面的所有叶目录的列表,您可以使用 这个问题。
然后,您可以构造一个像这样的 while 循环:
这应该给您一个起点。
To get a list of all the leaf directories below /big-directory, you can use the answer in this question.
Then, you can construct a while loop like this:
That should give you a starting point.
我遇到了同样的问题。在阅读了这个问题和其他几个问题之后,加上大量的试验和错误,我想出了以下解决方案:
我知道检查文件是否存在并不是严格必要的,但否则,脚本每次都会抛出错误查找不包含此文件的目录。
I encountered the same problem. After reading this question and several others, plus a lot of trial and error, I came up with the following solution:
I know that it's not strictly necessary to check whether the file exists, but otherwise, the script will throw an error every time it finds a directory that does not contain this file.