Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: funny subshell effect
- X-seq: zsh-users 19719
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: funny subshell effect
- Date: Fri, 9 Jan 2015 13:05:27 +0100
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=GqWSdCrbxhf9GKaBKSW+NgUFo70JcsTtbe/g9//c05Y=; b=xVoQN6LW9fic1Hb2VYZhjUKJzeAgW9PjHvx8ycPSqolMsgGAmG9cmPMZtxUKM1AY3v mGTGVRCV8phmYSP8/WIdcpxMjtYsg0B1qBlysWHTLf4rIGpWiIQ6iJfkOEQBlKnqSX9l g5YZohecNnFXgyU3r+xCdb42d5oO5hdksXn+TJYWkATWIt5zFDg4oeMILuj5dYNYjF1v T3zpublZ2/4Db/UZsJGghHI8OKaSqU5hthR73nUyxIZrKm1jAnEieBVxqycrw9MQDbUK 9OU7B/nmKih5RutTYEEvf9bjSP3i/iYsdEEbeh/XvehpXlz4BDVBkFaq6tYvd5Hevfqd 7J+g==
- In-reply-to: <AANLkTi=VUkvqOxo+OANG2AVYko-Zbq7LwLQoF68fbLev@mail.gmail.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <AANLkTi=VUkvqOxo+OANG2AVYko-Zbq7LwLQoF68fbLev@mail.gmail.com>
On Thu, Mar 10, 2011 at 12:18 AM, Mikael Magnusson <mikachu@xxxxxxxxx> wrote:
> This confused me for a few minutes, I was trying to play a random midi file with
> pmidi *(oe:REPLY=\$RANDOM:[1])
> but it plays the same one each time, but when i tried
> echo *(oe:REPLY=\$RANDOM:[1])
> it printed a different one each time
>
> % repeat 3; do echo .(e:REPLY=\$RANDOM:); done
> 17
> 25549
> 6369
> % repeat 3; do command echo .(e:REPLY=\$RANDOM:); done
> 5801
> 5801
> 5801
>
> Is this something that must be so? (My guess is yes, but it can't hurt to ask).
> (I know I can work around it easily by assigning to a var first).
I recently came up with a nicer workaround than making an explicit
variable, which is
() { pmidi $@ } *(oe:REPLY=\$RANDOM:[1])
for my original command in the thread. Since anonymous functions are
"builtin", the glob happens in the parent shell instead of the forked
subshell that runs pmidi, and everyone is (or at least I am) happy.
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author