I want to recursively convert all markdown files under ./src/
to html:
#!/bin/bash
function do_recursive_pandoc {
local markdown_src_file_extension=\*.markdown
local markdown_src_path="$1"
local html_output_path="$2"
mkdir "$html_output_path" 2>/dev/null
for i in $(find $markdown_src_path -name $markdown_src_file_extension 2>/dev/null | cut --delimiter='/' --fields=2- )
do
mkdir "$html_output_path"/$(dirname "$i") 2>/dev/null
pandoc -rmarkdown -whtml "$markdown_src_path"/"$i" --output="$html_output_path"/"$i".html
done
}
do_recursive_pandoc "src" "output"
But if I have space in file paths or names bash will count them as multiple items in for
loop, for example if I have:
./src/dir 1/foo.markdown
this script will make ./output/1
directory instead of making ./output/dir 1/
and tries converting ./src/dir
and ./src/1/foo.markdown
instead of ./src/dir 1/foo.markdown
How I can fix that?