[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] bash variable interpolation
From: |
Peng Yu |
Subject: |
Re: [Help-bash] bash variable interpolation |
Date: |
Thu, 19 Mar 2015 19:14:25 -0500 |
On Thu, Mar 19, 2015 at 7:04 PM, Eduardo A. Bustamante López
<address@hidden> wrote:
>> 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
This is essentially a parser, which definitely could be a solution.
But since bash has the parsing capability, it might be better to reuse
whatever already implemented in bash.
> 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.
There are very complex bash variables (array, subarray, etc). I'm not
sure this code would be robust against all possible usages (for
example, ":" seems to be missing).
> address@hidden ~ % x="'" y=IJK z=XYZ ./stencil <<< '"$x" $y $z'
> "'" IJK XYZ
>
> It's POSIX awk, so that should work for all awks.
--
Regards,
Peng
- Re: [Help-bash] bash variable interpolation, (continued)
- Re: [Help-bash] bash variable interpolation, Eduardo A . Bustamante López, 2015/03/19
- Re: [Help-bash] bash variable interpolation,
Peng Yu <=
- Re: [Help-bash] bash variable interpolation, Eduardo A . Bustamante López, 2015/03/19
- Re: [Help-bash] bash variable interpolation, Greg Wooledge, 2015/03/20
- Re: [Help-bash] bash variable interpolation, Peng Yu, 2015/03/20
- Re: [Help-bash] bash variable interpolation, Dan Douglas, 2015/03/21