Setting local variables for 'erb' command-line tool

I have a bunch of *.erb files which I would like to expand using the
‘erb’ command-line tool from within a shell script.

However, I can’t see how to set local variables so that <%= foo %>
works, other than piping the input onto stdin whilst prepending a
section like this:

<%
foo=123
bar=“baz”
%>

Am I being dense here, or is this the only way to do it?

Thanks,

Brian.

On Oct 14, 2010, at 8:21 AM, Brian C. wrote:

%>

Am I being dense here, or is this the only way to do it?

erb has a command-line switch to require a library. That library could
define top-level methods to serve as your local variables. Just a
thought.

James Edward G. II

James Edward G. II wrote in post #950195:

erb has a command-line switch to require a library. That library could
define top-level methods to serve as your local variables. Just a
thought.

Thanks for that idea.

What I’m doing for now is:

erb -T - erb.conf src.erb

where erb.conf contains local variable definitions:

<%
foo=“bar”
… etc
-%>

This is working fine, except that any errors in src.erb are reported
with an offset line number. e.g.

templates/wrapper.sh.erb:41: warning: found = in conditional, should be

(error actually in line 26 of that file, and erb.conf is 15 lines long)

Cheers,

Brian.