Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: command substitution: zsh waits until command exits
- X-seq: zsh-users 12267
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: zsh-users@xxxxxxxxxx
- Subject: Re: command substitution: zsh waits until command exits
- Date: Fri, 30 Nov 2007 07:37:19 -0800
- In-reply-to: <20071130133943.GG5855@xxxxxxxxxxxxxxxxxxx>
- Mailing-list: contact zsh-users-help@xxxxxxxxxx; run by ezmlm
- References: <20071130133943.GG5855@xxxxxxxxxxxxxxxxxxx>
On Nov 30, 2:39pm, Vincent Lefevre wrote:
}
} but doesn't say when zsh does the substitution and runs the main
} command (it should be clarified).
Look earlier in that man page. Almost the first thing it says is:
The following types of expansions are performed in the indicated
order in five steps:
with "Command Substitution" listed as happening at the third step,
... in left-to-right fashion.
(i.e., in the order it is found when scanning the command line).
} For instance, with the following
} command
}
} echo $(echo foo; exec >&-; sleep 2)
}
} zsh waits for 2 seconds before outputting 'foo'. However, since the
} standard output fd of the substituted command has been closed, I assume
} that zsh should be able to replace $(echo foo; exec >&-; sleep 2) by
} 'foo' and run the main command before the command inside $(...) exits.
} Is this a bug?
That really has nothing to do with "when zsh does the substitution" and
everything to do with job control. It's not a bug.
} Otherwise, is there a way to do what I wish (without temporary files)?
Sure -- background the command yourself, e.g.:
echo $({ echo foo ; exec >&- ; sleep 2; echo bar >/dev/tty } &)
} More precisely, I want to do something like:
}
} some_command $(xterm -e 'tty >&3; exec 3>&-; sleep 999999' 3>&1)
}
} so that some_command can write data to the xterm (in addition to the
} normal output).
That one is a bit tricky and the problem is that xterm doesn't close
the descriptors that it passes through to the command it's running, so
even when "exec 3>&-" runs *inside* the xterm, the descriptor is still
open. So you have to run xterm in a way that it's descriptors don't
matter. Something like:
echo $(coproc xterm -e 'tty >&3; sleep 999999' 3>&1 ; read -E <&p)
Messages sorted by:
Reverse Date,
Date,
Thread,
Author