help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-bash] bash variable interpolation


From: Eduardo A . Bustamante López
Subject: Re: [Help-bash] bash variable interpolation
Date: Thu, 19 Mar 2015 18:04:30 -0600
User-agent: Mutt/1.5.23 (2014-03-12)

> The real problem is that I want to replace some bash variables in a
> file and then print the output.
This is hard to do safely. The simplest approaches (eval, sed) will lead
to arbitrary code execution, or to an escaping mess.

> Please let me know if there is a convenient solution in bash.

I wrote: https://raw.githubusercontent.com/dualbus/myscripts/master/bin/stencil

Some time ago, precisely to deal with this issue. It's safe to use, because it
doesn't do any evaluation. It just replaces stuff that looks like bash
parameter expansions.

address@hidden ~ % x="'" y=IJK z=XYZ ./stencil <<< '"$x" $y $z'                 
              
"'" IJK XYZ

It's POSIX awk, so that should work for all awks.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]