Casey Flynn
Casey Flynn

Reputation: 14038

Bash script iterate over files recusively and save output to file with identical name but different extension

I'm trying to recursively iterate over all my .html files in a directory and convert them to .jade using a bash script.

#!/bin/bash
for f in ./*.html ./**/*.html ; do
  cat $f | html2jade -d > $f + '.jade';
done;

Naturally the $f + '.html' bit isn't correct. How might I fix this?

Upvotes: 1

Views: 409

Answers (2)

Gilles Quénot
Gilles Quénot

Reputation: 185161

#!/bin/bash
shopt -s globstar

for f in **/*.html; do
    html2jade -d < "$f" > "${f%.html}.jade"
done

Upvotes: 4

Ignacio Vazquez-Abrams
Ignacio Vazquez-Abrams

Reputation: 798676

Concatenation is the default for most cases.

... > "$f.jade"

Also:

html2jade ... < "$f"

And:

... > "${f%.html}.jade"

Upvotes: 1

Related Questions