Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: broken random variable
- X-seq: zsh-workers 44854
- From: Sebastian Gniazdowski <sgniazdowski@xxxxxxxxx>
- To: ". ." <apatiskogen@xxxxxxxxxx>
- Subject: Re: broken random variable
- Date: Sat, 19 Oct 2019 11:48:28 +0200
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=VYtmN4eqFyCky9RnqfmhynIw57pk6I44TZ8N/5+9Tsc=; b=MowI+aEwxevOcZ6y2wANSLZkh6Og2OGC/IbnUX91448MFtlSqQF81wu2dsrbROvVum W2lDM3chbhSz+vywzRXMNQCBebC5mb8kRhAQesgoUTmIVwiMxhiurdWoencrFlGjbpD8 paoVZJr5Cm2avcmLPfOqdRa8pLLEi4y5w1BtBKlXpGPceC01fkuxw2dXJF4DkYLlPs+x BL0fgTdu2r67+sNlkw/M42xMn9VVQIKerrNFjCg+Lo3q/esVau7ItLYThM6v0oTdKUxA 2nchVY2tNdwyJ7oeFEIm2DGHc3blZQrDdQ/8gcD0LcpnFWW/mKQ246Fab3057D4PgzXl K/CA==
- In-reply-to: <8724321571463531@myt3-a2a42ac8caa6.qloud-c.yandex.net>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <8724321571463531@myt3-a2a42ac8caa6.qloud-c.yandex.net>
On Sat, 19 Oct 2019 at 07:39, . . <apatiskogen@xxxxxxxxxx> wrote:
>
> Hello, zsh-workers
>
> I found a bug in the $RANDOM variable; on OpenBSD, the command "echo $RANDOM | tee" will print the same number
> across different executions of the same command, and the value of "echo $RANDOM" will be the same as the last value.
That's because Zsh is different from other shells in one regard: for the pipe:
A | B
it runs A in a subshell and B in the current shell, while other shells
like Bash run A in the current shell and B in the subshell. This is a
very nice feature, as it allows to do:
cat /some/file | while read line; do some_var=…; done
print $some_var
and the side-effects of this pipe will survive to the `print'.
So, the `echo $RANDOM | tee` will print the same value because the
$RANDOM will be read in a subshell, meaning that a fork() will be done
and the random-seed will be left unchanged in the outer process.
--
Sebastian Gniazdowski
News: https://twitter.com/ZdharmaI
IRC: https://kiwiirc.com/client/chat.freenode.net:+6697/#zplugin
Blog: http://zdharma.org
Messages sorted by:
Reverse Date,
Date,
Thread,
Author