On Friday, October 05, 2012 05:16:13 PM Chet Ramey wrote:
> On 10/4/12 6:58 PM, Dan Douglas wrote:
>
> > As an aside, mksh has an interesting syntax to assign a heredoc result
directly to a variable:
> >
> > # mksh
> >
> > var=<<EOF
> > ...
> > EOF
> >
> > This is optimized to happen in memory with no temporary file.
>
> Is that anything more than syntactic sugar? It doesn't seem different
> enough from multi-line double- or single-quoted strings to make it worth
> adding.
It's not the greatest choice of syntax considering x=<<EOF is already a valid
simple command. There would have to be a POSIX mode exception, and I can't
imagine how many of dark corners would be introduced by supporting it for all
assignments in general.
Better would be to add a type of quoting for specifying string literals
without concern for nested quotes or escapes, especially for strings that are
code. Abusing the heredoc as a form of quoting is too messy for interactive
use, only slightly less messy in a script, and not quite the right thing when
all you really want is to inject a string someplace without the shell touching
it.
--
Dan Douglas