Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: RANDOM shell expansion
- X-seq: zsh-workers 54067
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Philippe Altherr <philippe.altherr@xxxxxxxxx>
- Cc: Luis Estrozi <lestrozi@xxxxxxxxx>, zsh-workers@xxxxxxx
- Subject: Re: RANDOM shell expansion
- Date: Tue, 11 Nov 2025 08:02:55 -0800
- Archived-at: <https://zsh.org/workers/54067>
- In-reply-to: <CAGdYchv_EbF6cz8uaLH-naSqne3C58zdWunTnyjW+tYqy=txpQ@mail.gmail.com>
- List-id: <zsh-workers.zsh.org>
- References: <CAFy7FXim5vU+ny70+VLoMQ1TJjydw6-mY212F6EuuYcpZB_Y=g@mail.gmail.com> <CAGdYchv_EbF6cz8uaLH-naSqne3C58zdWunTnyjW+tYqy=txpQ@mail.gmail.com>
On Tue, Nov 11, 2025 at 3:58 AM Philippe Altherr
<philippe.altherr@xxxxxxxxx> wrote:
>
> The reason for the difference is that Zsh evaluates the redirection in the process of the affected command. echo and false are builtins. They are run and their redirections are evaluated in the running Zsh process. timeout is an external command. It is run and its redirection is evaluated in a forked process.
This is correct, but it's not the whole story. Zsh defines $RANDOM as
a *repeatable* sequence of random numbers:
The values of RANDOM form an intentionally-repeatable pseudo-random
sequence; subshells that reference RANDOM will result in identical
pseudo-random values unless the value of RANDOM is referenced or
seeded in the parent shell in between subshell invocations.
> On Tue, Nov 11, 2025 at 11:28 AM Luis Estrozi <lestrozi@xxxxxxxxx> wrote:
>>
>> I tried this on bash and it works as expected.
Bash does not define RANDOM as repeatable. Subshells / forks get a
new instantiation of RANDOM with new values.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author