How To Generate BASH Shell Scripts From File Templates?


I'm trying to create a File Template for a shell script that produces cover scripts for Java CLI programs.

Because of the degree of similarity between the Velocity and BASH syntax, I'm having trouble getting the escaping right, or so it seems.

The problematic BASH construct involves the use of its array variables. In order to accmulate successively generated entries of an array, this notation is used:

If I only escape (as in backslash prefix) the dollar sign, I get a parsing error when I try to instantiate the template. It refers to the "[@]" as the point of failure. I can avoid this by instead escaping the left curly-brace or the array variable ("arrayVar"). However, when I do this, the backslash appears in the output of the template instantiation.

Every variation on the escaping I've tried either gives spurious backslashes in the output or a syntax error when attempting to instantiate the template.

I haven't been able to find any information on generating these kinds of constructs using Velocity either on the Web or in the IntelliJ Community forum.

Can anyone suggest to me how to escape this conundrum?


Randall Schulz

Please sign in to leave a comment.