[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 <martijn@inlv.org> 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.
- Assigning to BASHPID fails silently, Martijn Dekker, 2016/10/17
- Re: Assigning to BASHPID fails silently, Eduardo A . Bustamante López, 2016/10/18
- Re: Assigning to BASHPID fails silently, Chet Ramey, 2016/10/19
- Re: Assigning to BASHPID fails silently, Chet Ramey, 2016/10/20
- Re: Assigning to BASHPID fails silently, Dan Douglas, 2016/10/20
- Re: Assigning to BASHPID fails silently, Chet Ramey, 2016/10/20
- Re: Assigning to BASHPID fails silently, Chet Ramey, 2016/10/20