Sysop: | Amessyroom |
---|---|
Location: | Fayetteville, NC |
Users: | 43 |
Nodes: | 6 (0 / 6) |
Uptime: | 108:20:06 |
Calls: | 290 |
Files: | 905 |
Messages: | 76,683 |
(bash) What is the difference between << and <<<, from a functionality
POV? I.e., is there anything you can do with one but not the other?
I'm talking about this:
$ cmd << 'EOF'
...
...
EOF
$
vs.
$ cmd <<< '
...
...
'
$
Of course I know, as does everybody, that << is legacy and <<< is new, but
it begs the question: Why was <<< added to the language?
Note that I use both constructs, as the mood suits me, but I just got to thinking that maybe <<< doesn't actually add any new functionality.
Note that I use both constructs, as the mood suits me, but I just got to
thinking that maybe <<< doesn't actually add any new functionality.
It's actually a restriction since it doesn't allow (e.g.) to control
variable expansion (as is possible with escaping the tag ('EOF' in
your example, which prevents expansion, vs. unquoted/unescaped EOF ).
So what remains then is only '<<<' being a one-liner shortcut and
the '<<-' (plus the '<<#' in ksh) features to control indentation,
I suppose.
In article <vcbb68$3dfds$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
...
Note that I use both constructs, as the mood suits me, but I just got to >>> thinking that maybe <<< doesn't actually add any new functionality.
It's actually a restriction since it doesn't allow (e.g.) to control
variable expansion (as is possible with escaping the tag ('EOF' in
your example, which prevents expansion, vs. unquoted/unescaped EOF ).
Well, not really. I can always do:
$ cmd << EOF
$(fortune)
EOF
$
and/or:
$ cmd <<< "
$(fortune)
"
$
Same diff, innit?
So what remains then is only '<<<' being a one-liner shortcut and
the '<<-' (plus the '<<#' in ksh) features to control indentation,
I suppose.
In article <vcc7qk$3j1r6$1@dont-email.me>,
Janis Papanagnou <janis_papanagnou+ng@hotmail.com> wrote:
...
So what remains then is only '<<<' being a one-liner shortcut and
the '<<-' (plus the '<<#' in ksh) features to control indentation,
I suppose.
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 <<<.
Note that I use both constructs, as the mood suits me, but I just got to thinking that maybe <<< doesn't actually add any new functionality.
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.
As might have already got obvious, though, I use the '<<<' syntax
for other purposes than for such template files; for one-liners. In
that context mixed quote forms are not typical (IME) so that this
property of '<<' is not that important for me to have in '<<<'.[*]
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:
In article <20240917132221.49@kylheku.com>,
Kaz Kylheku <643-408-1753@kylheku.com> wrote:
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:
Perhaps you misread my post. Perhaps you misread "superiority" as "inferiority". I admit that the two words do look pretty similar.
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?
If you want to produce some templated text with shell interpolation,
with minimal uncertainties with regard to quoting, <<< is in fact
inferior.
Perhaps you misread my post. Perhaps you misread "superiority" as "inferiority". I admit that the two words do look pretty similar.
In article <20240917140842.283@kylheku.com>,
Kaz Kylheku <643-408-1753@kylheku.com> wrote:
...
If you want to produce some templated text with shell interpolation,
with minimal uncertainties with regard to quoting, <<< is in fact
inferior.
You really might want to go back and check up on your reading skills.
Note: We are in violent agreement.