Sujet : Re: Different variable assignments
De : Lem (at) *nospam* none.invalid (Lem Novantotto)
Groupes : comp.unix.shellDate : 13. Oct 2024, 00:07:41
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <veevft$aqpc$1@dont-email.me>
References : 1 2 3 4 5 6 7 8
User-Agent : Pan/0.160 (Toresk; )
Il Sat, 12 Oct 2024 17:57:16 +0200, Frank Winkler ha scritto:
I'm still thinking about the difference between "< <(...)" and "<<<`...`"
As already pointed out by Lawrence:
1) "command2 <<<`command1`": `command2`, equal to the preferable[*]
$(command2), can be seen as the output of command2: a string. So with
<<< you are telling the shell to take this string as input on the
standard input of command2. So: execute command1, then take its output
as the input of command2. This is called *command* substitution:
substitution of a command with its output.
[*] No characters are special between parenthesis: easier.
2) "command2 < <(process_of_command1)": here process, which is the
"active running instance" of command1 - enough: remove the difference,
think of command1 and stop - is run with its output connected to a
named FIFO pipe file (or to some file in /dev/fd).
So <(process_of_command1) is expanded as the name of this file.
The first < is simple input redirection.
So: execute command1, connect the output of its process to a special
file, redirect this special file to input of command2.
This is called *process* output substitution: substitute a
process with the name of its output file.
Process substitution does work only on systems supporting named pipes
or /dev/fd/... so it's less universal than command substitution.
Some practical differences. For example, try:
$ cat <<<$(while true; do echo yes; done)
Nothing: cat is waiting for the other stuff to end. But it won't end,
in this case! Gawsh!
$ cat < <( while true; do echo yes; done)
Rock'n'roll!
And I would be happy with this one if there was a notation "the other
way round" ... something like "... >>> $var"
You're more the straightforward type of guy, eh! That's fine! ;)
But, sorry, '>>>' is still to come. In bash, at least. :-)
-- Bye, Lem