Re: Another 'What's the diff Q" (LDo will like this)

Liste des Groupes 
Sujet : Re: Another 'What's the diff Q" (LDo will like this)
De : 643-408-1753 (at) *nospam* kylheku.com (Kaz Kylheku)
Groupes : comp.unix.shell
Date : 17. Sep 2024, 21:34:25
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <20240917132221.49@kylheku.com>
References : 1 2 3 4 5
User-Agent : slrn/pre1.0.4-9 (Linux)
On 2024-09-17, Kenny McCormack <gazelle@shell.xmission.com> wrote:
In article <vccesq$3kjv7$1@dont-email.me>,
Janis Papanagnou  <janis_papanagnou+ng@hotmail.com> wrote:
...
I just thought of something.  Suppose your included text contains both
single and double quotes.  This will not be an issue with <<, but will
require extra effort (more than I care to expend!) with <<<.
>
That's actually the property I like with here-docs; that you can
write your template-like text inside the shell-program text as it
shall (and will) be seen at the target side, both forms of quotes
inclusive.
>
Right.  The point I was making is that this rates as a superiority of <<
over <<< - and answers the question posted in the OP: Is there anything one
can do that the other cannot?

Many years ago, I was working on an embedded Linux distro (from
scratch). For text files installed on the target system, like /etc,
I had a Makefile-based thing which could preprocess files with several
preprocessors, based on their suffix. One of the preprocessors was
shell. For those files, what the Makefile did was dynamically
generate a temporary script like this:

  cat <<ENDMARKER
  # pasted copy of the template file here
  ENDMARKER

and then execute the temporary script.

What I'm getting at is that nothing had to be done to the template
file text.

If <<< is used, then the whole template is a quoted field, using
either single quotes and double quotes.

We cannot generate this:

  cat <<<'
  # pasted copy of the template file here
  '

Because the template file could contain single quotes, which would
have to be turned into '\''.

Similarly, we cannot blindly generate this:

  cat <<<"
  # pasted copy of the template file here
  "

because double quotes need escaping now. This is the variant we
would have to use in the templating system because the template
files relied on interpolating the output of variables and
shell commands:

  $(for x in a b c; do echo blah $x; done)

So in fact this is backwards; the <<< syntax can likely produce
all the output that << can, but it requires quoting, which requires
escaping that << does not require.

E.g. we can do this:

  $ cat <<!
  '$USER
  !
  'kaz

There is an unbalanced quote there, which is just a verbatim
character. Not a problem in a here-doc.

In this sense, the <<< syntax does less: it requires quoting, which
protects fewer character sequences from being interpeted specially. It
does so for the benefit of its inline syntax.

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca

Date Sujet#  Auteur
17 Sep 24 * Another 'What's the diff Q" (LDo will like this)15Kenny McCormack
17 Sep 24 +* Re: Another 'What's the diff Q" (LDo will like this)13Janis Papanagnou
17 Sep 24 i`* Re: Another 'What's the diff Q" (LDo will like this)12Kenny McCormack
17 Sep 24 i `* Re: Another 'What's the diff Q" (LDo will like this)11Janis Papanagnou
17 Sep 24 i  +- Re: Another 'What's the diff Q" (LDo will like this)1Kenny McCormack
17 Sep 24 i  `* Re: Another 'What's the diff Q" (LDo will like this)9Kenny McCormack
17 Sep 24 i   `* Re: Another 'What's the diff Q" (LDo will like this)8Janis Papanagnou
17 Sep 24 i    `* Re: Another 'What's the diff Q" (LDo will like this)7Kenny McCormack
17 Sep 24 i     `* Re: Another 'What's the diff Q" (LDo will like this)6Kaz Kylheku
17 Sep 24 i      `* Re: Another 'What's the diff Q" (LDo will like this)5Kenny McCormack
17 Sep 24 i       +* Re: Another 'What's the diff Q" (LDo will like this)3Kaz Kylheku
18 Sep 24 i       i`* Re: Another 'What's the diff Q" (LDo will like this)2Kenny McCormack
18 Sep 24 i       i `- Re: Another 'What's the diff Q" (LDo will like this)1Kaz Kylheku
18 Sep 24 i       `- Re: Another 'What's the diff Q" (LDo will like this)1Kaz Kylheku
17 Sep 24 `- Re: Another 'What's the diff Q" (LDo will like this)1Kaz Kylheku

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal