I'm looking to write a bash script that will recursively find all .less
files in a directory and create a .css
file with the same name in a parent css
directory using lessc
. Visually it looks like this.
Before:
/css
/less
a.less
b.less
/whatever
/css
/less
c.less
d.less
After:
/css
a.css
b.css
/less
a.less
b.less
/whatever
/css
c.css
d.css
/less
c.less
d.less
What I've been able to figure out so far is that I can find all the files using:
find . -name *.less
And I can generate individual files using:
lessc foo.less > ../css/foo.css
My problem comes trying to pipe the results of the find
into lessc
. Per this question I can see how the results of find
can be piped into cat
, but the same approach isn't working for me with lessc
.
In general I'm just having trouble putting the pieces together. Any help would be appreciated.
Thanks.
Edit
This is what worked for me. Thanks @ghoti!
find . -name \*.less -print | sed -rne 's:(.*)/less/([^/]+).less$:lessc & > \1/css/\2.css:p' | sh