Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: convolutions



07.11.2015, 18:37, "Ray Andrews" <rayandrews@xxxxxxxxxxx>:
> On 11/06/2015 10:38 PM, Mikael Magnusson wrote:
>>  No, because 'expanding into "\e"' means nothing useful, did you mean a
>>  literal backslash followed by an e, or a literal escape?
>
> It's not arguable sir. If you found it vague, then you found it vague,
> but to me:
>
>       " \e[31;1m "
>
> ... is very obviously a color code which I hold in my variable " ${red}
> " and I want to expand it inside a file.
>
>>  If you store the string in a parameter and echo that parameter, the
>>  color variables also don't expand.
>>>  So you have a file with "${red}" in it, and you want to read in the
>>>  file, and substitute the value of any parameter references.
>
> Exactly.
>>>  Moreover,
>>>  these parameters are not defined in the file, but are set in the shell
>>>  environment and you happen to know that they are string
>>>  representations of color escape sequences, and you want to expand
>>>  these as well.
>
> Of course. Who but me knows what's in my environment variables?
>>>  If your file has a semicolon in it somewhere, then your command will
>>>  run arbitrary code. Bart's example doesn't have that exact problem,
>>>  but will still execute code if there are things like $(command) in the
>>>  file.
>
> Yes, I know how dangerous eval is, that's why I'm asking for a better
> idea--some way of expanding parameters inside a file. Not just color
> variables really, any variables.

I have no idea why you need such a thing, and need this *in zsh*. This is a job for a template engine, numerous of which exist for every script language out there used for writing something for web (which does not include zsh). Otherwise there already were three solutions, with different downsides. Also see http://stackoverflow.com/questions/2914220/bash-templating-how-to-build-configuration-files-from-templates-with-bash/2916159?noredirect=1#comment46735969_2916159, this can be ported to zsh very easily (note the comments).

Still asking this here looks either like an XY problem or wrong choice of instruments.



Messages sorted by: Reverse Date, Date, Thread, Author