You are not logged in.

#1 2009-09-08 02:43:13

kandrews
Member
Registered: 2007-04-21
Posts: 119

[SOLVED] help with shell script to run markdown on a bunch of files

I'm trying to make a script to run markdown on all the *.md files in a directory and make a bunch of *.html files with the same name before the extension.  I've looked at some bulk renaming scripts,  but I don't really want to copy or move anything.  I just want to send the output of markdown to a new file.  How can I do this?

#!/bin/sh

# run markdown on each md file; output a file with same name 
# but .html extension.
make() 
{
    NOTES="*.md"
    for note in $NOTES
    do
        # TODO: how to substitute extensions?
        markdown $note > # $note but with .html instead of markdown
    done
}

# clean out all the html files
clean() 
{
    rm *.html
}

case $1 in
make)
    make
    ;;
clean)
    clean
    ;;
*)
    echo "usage: webify [make|clean]"
    ;;
esac

Last edited by kandrews (2009-09-08 03:04:55)

Offline

#2 2009-09-08 02:46:35

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,485
Website

Re: [SOLVED] help with shell script to run markdown on a bunch of files

markdown $note >  $(basename $note .md).html

Offline

#3 2009-09-08 03:04:37

kandrews
Member
Registered: 2007-04-21
Posts: 119

Re: [SOLVED] help with shell script to run markdown on a bunch of files

thanks a bunch!

Offline

Board footer

Powered by FluxBB