* Where is this =(:) construct documented?
@ 2021-06-11 19:17 Zach Riggle
2021-06-11 19:18 ` Zach Riggle
2021-06-11 19:53 ` Stephane Chazelas
0 siblings, 2 replies; 8+ messages in thread
From: Zach Riggle @ 2021-06-11 19:17 UTC (permalink / raw)
To: zsh-workers
It's insane, cool, and I can't find this documented anywhere. It
creates a temporary file that is automatically deleted... but only
after the line / expression terminates.
( ... ) creates a subshell (terminology?)
( : ) creates a subshell that does nothing
=bash evaluates to the path to bash, e.g. /usr/bin/bash
$(...) captures the output of a subshell, e.g. x=$(echo foo)
If follows, then, that =(:) shows the path to... what? Apparently, a
scope-tracked, auto-deleting temporary file. *Where is this
documented?*
# wat.zsh ####
wat() {
>&2 echo IN WAT
>&2 ls -la "$1"
echo "$1"
}ls -la $(wat =(:))
#############
# example #####
$ zsh wat.sh
IN WAT
-rw------- 1 zachriggle wheel 0 Jun 11 14:13 /tmp/zshfMERth
ls: /tmp/zshfMERth: No such file or directory
#############
What's more insane is that the temporary file will be auto-populated
with the output of the =() construct. Where is THAT documented?
#############
$ (){ echo $1; cat $1 } =( echo allo )
/tmp/zshpfFAOp
allo
#############
Zach Riggle
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Where is this =(:) construct documented?
2021-06-11 19:17 Where is this =(:) construct documented? Zach Riggle
@ 2021-06-11 19:18 ` Zach Riggle
2021-06-11 19:53 ` Stephane Chazelas
1 sibling, 0 replies; 8+ messages in thread
From: Zach Riggle @ 2021-06-11 19:18 UTC (permalink / raw)
To: zsh-workers
Formatting fix, I accidentally a newline.
# wat.zsh ####
wat() {
>&2 echo IN WAT
>&2 ls -la "$1"
echo "$1"
}
ls -la $(wat =(:))
#############
Zach Riggle
On Fri, Jun 11, 2021 at 2:17 PM Zach Riggle <zachriggle@gmail.com> wrote:
>
> It's insane, cool, and I can't find this documented anywhere. It
> creates a temporary file that is automatically deleted... but only
> after the line / expression terminates.
>
> ( ... ) creates a subshell (terminology?)
> ( : ) creates a subshell that does nothing
> =bash evaluates to the path to bash, e.g. /usr/bin/bash
> $(...) captures the output of a subshell, e.g. x=$(echo foo)
>
> If follows, then, that =(:) shows the path to... what? Apparently, a
> scope-tracked, auto-deleting temporary file. *Where is this
> documented?*
>
> # wat.zsh ####
> wat() {
> >&2 echo IN WAT
> >&2 ls -la "$1"
> echo "$1"
> }ls -la $(wat =(:))
> #############
>
> # example #####
> $ zsh wat.sh
> IN WAT
> -rw------- 1 zachriggle wheel 0 Jun 11 14:13 /tmp/zshfMERth
> ls: /tmp/zshfMERth: No such file or directory
> #############
>
> What's more insane is that the temporary file will be auto-populated
> with the output of the =() construct. Where is THAT documented?
>
> #############
> $ (){ echo $1; cat $1 } =( echo allo )
> /tmp/zshpfFAOp
> allo
> #############
>
>
> Zach Riggle
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Where is this =(:) construct documented?
2021-06-11 19:17 Where is this =(:) construct documented? Zach Riggle
2021-06-11 19:18 ` Zach Riggle
@ 2021-06-11 19:53 ` Stephane Chazelas
2021-06-11 19:58 ` Roman Perepelitsa
2021-06-11 20:04 ` Stephane Chazelas
1 sibling, 2 replies; 8+ messages in thread
From: Stephane Chazelas @ 2021-06-11 19:53 UTC (permalink / raw)
To: Zach Riggle; +Cc: zsh-workers
2021-06-11 14:17:08 -0500, Zach Riggle:
> It's insane, cool, and I can't find this documented anywhere. It
> creates a temporary file that is automatically deleted... but only
> after the line / expression terminates.
[...]
> What's more insane is that the temporary file will be auto-populated
> with the output of the =() construct. Where is THAT documented?
[...]
See
info zsh "Process Substitution"
Or:
https://zsh.sourceforge.io/Doc/Release/Expansion.html#Process-Substitution
That's the third form of process substitution.
ksh introduced the first two <(...) and >(...) in the 80s. zsh
added that third form in the 90s.
While A <(B) and A >(B) are IPC mechanisms in that A and B are
started concurrently and connected via a pipe (<(B) and >(B)
expand respectively to the path of the reading of a pipe and
writing end of a pipe, in A =(B), B is started first, its output
collected into a temp file, and the path of that temp file
passed to A when B has finished (and later removed when A
finishes).
--
Stephane
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Where is this =(:) construct documented?
2021-06-11 19:53 ` Stephane Chazelas
@ 2021-06-11 19:58 ` Roman Perepelitsa
2021-06-11 20:04 ` Stephane Chazelas
1 sibling, 0 replies; 8+ messages in thread
From: Roman Perepelitsa @ 2021-06-11 19:58 UTC (permalink / raw)
To: Zach Riggle, Zsh hackers list
On Fri, Jun 11, 2021 at 9:53 PM Stephane Chazelas <stephane@chazelas.org> wrote:
>
> That's the third form of process substitution.
And the colon in =(:) is a builtin that does nothing (the same as
true). It's mandated by POSIX.
Roman.
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Where is this =(:) construct documented?
2021-06-11 19:53 ` Stephane Chazelas
2021-06-11 19:58 ` Roman Perepelitsa
@ 2021-06-11 20:04 ` Stephane Chazelas
2021-06-11 20:39 ` Zach Riggle
1 sibling, 1 reply; 8+ messages in thread
From: Stephane Chazelas @ 2021-06-11 20:04 UTC (permalink / raw)
To: Zach Riggle, zsh-workers
2021-06-11 20:53:22 +0100, Stephane Chazelas:
[...]
> info zsh "Process Substitution"
[...]
For information, searching in info (with / or s or Ctrl+S) these
days uses extended regexps. So, to search for =(, you need to
search for =\( or toggle regexp matching off first with R. See
info info / for details.
[...]
> That's the third form of process substitution.
>
> ksh introduced the first two <(...) and >(...) in the 80s. zsh
> added that third form in the 90s.
Already in ksh86. In ksh86 you could actually also use A (B) in
place of A <(B) though it looks like it was removed in later
versions. rc also had process substitution with a different
syntax IIRC.
See also:
https://unix.stackexchange.com/questions/49918/when-was-process-substitution-first-introduced/49952#49952
and
https://unix.stackexchange.com/questions/181937/how-create-a-temporary-file-in-shell-script/181996#181996
--
Stephane
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Where is this =(:) construct documented?
2021-06-11 20:04 ` Stephane Chazelas
@ 2021-06-11 20:39 ` Zach Riggle
2021-06-14 12:44 ` Vincent Lefevre
0 siblings, 1 reply; 8+ messages in thread
From: Zach Riggle @ 2021-06-11 20:39 UTC (permalink / raw)
To: Zach Riggle, zsh-workers
Thanks for the help, all! This was impossible to Google for!
Most obfuscated I could make it (to mess with coworkers) is...
(){<<<$1} =(:)
Zach Riggle
On Fri, Jun 11, 2021 at 3:04 PM Stephane Chazelas <stephane@chazelas.org> wrote:
>
> 2021-06-11 20:53:22 +0100, Stephane Chazelas:
> [...]
> > info zsh "Process Substitution"
> [...]
>
> For information, searching in info (with / or s or Ctrl+S) these
> days uses extended regexps. So, to search for =(, you need to
> search for =\( or toggle regexp matching off first with R. See
> info info / for details.
>
> [...]
> > That's the third form of process substitution.
> >
> > ksh introduced the first two <(...) and >(...) in the 80s. zsh
> > added that third form in the 90s.
>
> Already in ksh86. In ksh86 you could actually also use A (B) in
> place of A <(B) though it looks like it was removed in later
> versions. rc also had process substitution with a different
> syntax IIRC.
>
> See also:
>
> https://unix.stackexchange.com/questions/49918/when-was-process-substitution-first-introduced/49952#49952
>
> and
>
> https://unix.stackexchange.com/questions/181937/how-create-a-temporary-file-in-shell-script/181996#181996
>
> --
> Stephane
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Where is this =(:) construct documented?
2021-06-11 20:39 ` Zach Riggle
@ 2021-06-14 12:44 ` Vincent Lefevre
2021-06-14 14:32 ` Stephane Chazelas
0 siblings, 1 reply; 8+ messages in thread
From: Vincent Lefevre @ 2021-06-14 12:44 UTC (permalink / raw)
To: Zach Riggle; +Cc: zsh-workers
On 2021-06-11 15:39:29 -0500, Zach Riggle wrote:
> Thanks for the help, all! This was impossible to Google for!
>
> Most obfuscated I could make it (to mess with coworkers) is...
>
> (){<<<$1} =(:)
You need to search in the man pages (I recommend to do that with
"man zshall" so that all zsh man pages are searched).
--
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: Where is this =(:) construct documented?
2021-06-14 12:44 ` Vincent Lefevre
@ 2021-06-14 14:32 ` Stephane Chazelas
0 siblings, 0 replies; 8+ messages in thread
From: Stephane Chazelas @ 2021-06-14 14:32 UTC (permalink / raw)
To: Zach Riggle, zsh-workers
2021-06-14 14:44:17 +0200, Vincent Lefevre:
> On 2021-06-11 15:39:29 -0500, Zach Riggle wrote:
> > Thanks for the help, all! This was impossible to Google for!
> >
> > Most obfuscated I could make it (to mess with coworkers) is...
> >
> > (){<<<$1} =(:)
>
> You need to search in the man pages (I recommend to do that with
> "man zshall" so that all zsh man pages are searched).
[...]
I wouldn't recommend man for a manual this big. I don't think
I've read zsh's man page in the last decade.
IMO, info is much more appropriate especially considering the
zsh manual there has a very good index and table of contents (i
and I commands with completion are your friends in info, zsh
also has completion for index entries so "info zsh topic<Tab>"
often works).
On some systems, you need to install a zsh-doc package or
equivalent though for the info pages to be available.
--
Stephane
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2021-06-14 14:33 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-06-11 19:17 Where is this =(:) construct documented? Zach Riggle
2021-06-11 19:18 ` Zach Riggle
2021-06-11 19:53 ` Stephane Chazelas
2021-06-11 19:58 ` Roman Perepelitsa
2021-06-11 20:04 ` Stephane Chazelas
2021-06-11 20:39 ` Zach Riggle
2021-06-14 12:44 ` Vincent Lefevre
2021-06-14 14:32 ` Stephane Chazelas
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).