bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Assigning to BASHPID fails silently


From: lolilolicon
Subject: Re: Assigning to BASHPID fails silently
Date: Fri, 21 Oct 2016 01:31:54 +0800

On Thu, Oct 20, 2016 at 11:32 PM, Martijn Dekker <address@hidden> wrote:
> #! /usr/local/bin/bash
> insubshell() {
>         return "$((BASHPID=$$))"
>         #                 ^ fatal typo
> }
> for ((i=0; i<10000; i++)); do insubshell; done
> echo $i
> insubshell || echo ok
> echo continuing
>
> The output of this script on my copy of bash-4.4.0 is consistently:
>
> | 0
> | continuing
>
> Clearly, that 0 should be 10000. The 'insubshell' function somehow
> manages to interrupt the 'for' loop.

It's not so much the for loop. See,

$ BASHPID= echo k
bash: BASHPID: readonly variable
k
$ BASHPID=; echo k
$ echo k
k

See the second k is not printed. bash simply aborts this command. In
your case, the for compound command.
The bug probably is very clear to Chet already.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]