On 28.08.2020 17:58, Kaz Kylheku wrote:
> On 2020-08-28, Janis Papanagnou <
janis_pa...@hotmail.com> wrote:
>> As done with sed, the awk way also doesn't need to use cat
>>
>> awk '...' <<-EOF
>> ...
>> EOF
>
> I would just do this:
> command <<EOF
> blah
> blah
> EOF
>
> That is idiomatic code.
Both versions are idiomatic, IMO, and standard; not sure why you think
the other idiom would not be one. But, frankly, I don't see much gain
to discuss that; I am using both versions as they seem to best fit to
the given program context. (Above I've just copied the original code.)
> Any coding convention or tool which doesn't like it can just bugger off.
It's the '-' version's property usually makes the code structure clearer
and thus increases readability and thus maintainability. The downside is
that at the same time it also decreases maintainability; invisible white
space differences in code are harder to maintain. (The OP's request is
one way to tackle that issue.)
>
> Adding superfluous complexity and execution cycles just to make the
> source code look prettier is a poor idea.
Opinions obviously differ. But I see where you're coming from.
There are two potential complexities here; runtime and code. For such
small pieces of template code the first one is typically negligible.
The second one (if one uses that idiom regularly) can be addrdessed by
using a function, say 'aligned_indent', so that the not really complex
but probably annoying awk/sed/whatever code is hidden.
aligned_indent <<EOT >outfile
...
EOT
> I will give you another reason for avoiding this. A here doc's
> body is supposed to be a template, with perhaps some variant
> pieces such as substituted variables.
>
> The non-variant parts are verbatim.
>
> If you indent it, it is no longer verbatim. A here doc may be derived
> from some original text somewhere; if whitespace is added, it doesn't
> match that text any more. Someone needing to keep the two in sync has
> to deal with the annoying indentation.
I've never had this case. I've done a lot with heredoc-templates; what
they had in common was that *I* was the one that defined the contents,
be it html-code, source code, data, whatever.
As mentioned already, I take that issue very pragmatically and don't
mind innovative code patterns like the one the OP quoted from SE.
One final remark for Kornshell users - the shell that I regularly use;
I think it's not widely known that ksh has that feature as a built-in.
With the syntax
cat <<# EOT
...
EOT
you get exactly what the OP asked for, without need for other code that
complicates the shell program's source code structure.
Janis
> [...]