I'm using Pandoc to convert Markdown to .docx - how do I remove the .md from the resulting filename?

Viewed 77

I've been using a shell script in Automator on MacOS (OSX) successfully, but my method retains the '.md' extension in the resulting filename.

For example, if I input the file myfile.md the output is myfile.md.docx

This is my script:

for f in "$@"
do
    if [[ "$f" = *.md ]]; then
        /Users/myname/opt/anaconda3/bin/pandoc -o "${f%}.docx" -f markdown -t docx $f && open "${f%}.docx"
    fi
done

Can anyone help me with this last step?

1 Answers

Use -o "${f%.*}.docx" to remove the original extension.

Related