# git-bisect: weird usage of read(1)

15 messages from 2008-08-11 to 2008-08-11. Participants: Francis Moreau, Johannes Schindelin, Mikael Magnusson, Reece Dunn, René Scharfe, Petr Baudis, Junio C Hamano.
Thread: https://gitlist.dev/t/14930

## Francis Moreau, 2008-08-11 13:57

Subject: git-bisect: weird usage of read(1)
Message-ID: <38b2ab8a0808110657y24ac9526wca4acea3bddaec00@mail.gmail.com>
URL: https://gitlist.dev/e/38b2ab8a0808110657y24ac9526wca4acea3bddaec00%40mail.gmail.com

```
Hello

I found this in git bisect:

              printf >&2 'Are you sure [Y/n]? '
              case "$(read yesno)" in [Nn]*) exit 1 ;; esac

which looks very weird since read(1) returns a status and not the
string reads from std input.

Am I missing something ?

Thanks
-- 
Francis

```

## Johannes Schindelin, 2008-08-11 14:15

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <alpine.DEB.1.00.0808111615260.24820@pacific.mpi-cbg.de.mpi-cbg.de>
URL: https://gitlist.dev/e/alpine.DEB.1.00.0808111615260.24820%40pacific.mpi-cbg.de.mpi-cbg.de
In-Reply-To: <38b2ab8a0808110657y24ac9526wca4acea3bddaec00@mail.gmail.com>

```
Hi,

On Mon, 11 Aug 2008, Francis Moreau wrote:

> I found this in git bisect:
> 
>               printf >&2 'Are you sure [Y/n]? '
>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
> 
> which looks very weird since read(1) returns a status and not the
> string reads from std input.
> 
> Am I missing something ?

Yes.  "$()" does not return the status, but the output.

Ciao,
Dscho

```

## Mikael Magnusson, 2008-08-11 14:16

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <237967ef0808110716l2a0a2a4je22c2a1b8c239f57@mail.gmail.com>
URL: https://gitlist.dev/e/237967ef0808110716l2a0a2a4je22c2a1b8c239f57%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0808111615260.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```
2008/8/11 Johannes Schindelin <Johannes.Schindelin@gmx.de>:
> Hi,
>
> On Mon, 11 Aug 2008, Francis Moreau wrote:
>
>> I found this in git bisect:
>>
>>               printf >&2 'Are you sure [Y/n]? '
>>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
>>
>> which looks very weird since read(1) returns a status and not the
>> string reads from std input.
>>
>> Am I missing something ?
>
> Yes.  "$()" does not return the status, but the output.

But there is no output, since read doesn't print anything...
case "$(read yesno; echo $yesno)" in [Nn]*) could work, but looks
a bit strange. read yesno; case $yesno in [Nn]*) would be the usual
way to do things i think?

-- 
Mikael Magnusson

```

## Francis Moreau, 2008-08-11 14:18

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <38b2ab8a0808110718x2f63608ga3d2d77e317ce4eb@mail.gmail.com>
URL: https://gitlist.dev/e/38b2ab8a0808110718x2f63608ga3d2d77e317ce4eb%40mail.gmail.com
In-Reply-To: <alpine.DEB.1.00.0808111615260.24820@pacific.mpi-cbg.de.mpi-cbg.de>

```
Hello

On Mon, Aug 11, 2008 at 4:15 PM, Johannes Schindelin
<Johannes.Schindelin@gmx.de> wrote:
> Hi,
>
> On Mon, 11 Aug 2008, Francis Moreau wrote:
>
>> I found this in git bisect:
>>
>>               printf >&2 'Are you sure [Y/n]? '
>>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
>>
>> which looks very weird since read(1) returns a status and not the
>> string reads from std input.
>>

sorry I should have said that there's a status but no output...

>> Am I missing something ?
>
> Yes.  "$()" does not return the status, but the output.
>

But what's the output in that case ?

-- 
Francis

```

## Reece Dunn, 2008-08-11 15:59

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <3f4fd2640808110859r148550d2h833dae05b9e6544e@mail.gmail.com>
URL: https://gitlist.dev/e/3f4fd2640808110859r148550d2h833dae05b9e6544e%40mail.gmail.com
In-Reply-To: <38b2ab8a0808110718x2f63608ga3d2d77e317ce4eb@mail.gmail.com>

```
2008/8/11 Francis Moreau <francis.moro@gmail.com>:
> Hello
>
> On Mon, Aug 11, 2008 at 4:15 PM, Johannes Schindelin
> <Johannes.Schindelin@gmx.de> wrote:
>> Hi,
>>
>> On Mon, 11 Aug 2008, Francis Moreau wrote:
>>
>>> I found this in git bisect:
>>>
>>>               printf >&2 'Are you sure [Y/n]? '
>>>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
>>>
>>> which looks very weird since read(1) returns a status and not the
>>> string reads from std input.
>>>
>
> sorry I should have said that there's a status but no output...
>
>>> Am I missing something ?
>>
>> Yes.  "$()" does not return the status, but the output.
>>
>
> But what's the output in that case ?

Using cygwin+bash, I get:

$ echo $(read yesno)
n

$ echo $(read yesno; echo $yesno)
n
n
$ $(read yesno) && echo yes || echo no
n
yes
$ $(read yesno) && echo yes || echo no
y
yes
$ case "$(read yesno)" in [Nn]*) echo "no" ;; esac
n
$ case "$(read yesno)" in [Nn]*) echo "no" ;; esac
y
$ case "$(read yesno; echo $yesno)" in [Nn]*) echo "no" ;; esac
n
no
$ case "$(read yesno; echo $yesno)" in [Nn]*) echo "no" ;; esac
y

So

>>>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac

does not work as expected. Replacing this with

               case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esac

would work as intended, as Mikael has pointed out.

- Reece

```

## René Scharfe, 2008-08-11 16:18

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <48A06659.6010004@lsrfire.ath.cx>
URL: https://gitlist.dev/e/48A06659.6010004%40lsrfire.ath.cx
In-Reply-To: <38b2ab8a0808110657y24ac9526wca4acea3bddaec00@mail.gmail.com>

```
Francis Moreau schrieb:
> I found this in git bisect:
> 
>               printf >&2 'Are you sure [Y/n]? '
>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
> 
> which looks very weird since read(1) returns a status and not the
> string reads from std input.

Good catch.  You need to press Ctrl-C in order to exit, answering "no"
means the same as "yes" here -- not very nice.  Care to send a patch?

Thanks,
René

```

## Francis Moreau, 2008-08-11 16:23

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <38b2ab8a0808110923u21d543f0qbc9dee0f99c97311@mail.gmail.com>
URL: https://gitlist.dev/e/38b2ab8a0808110923u21d543f0qbc9dee0f99c97311%40mail.gmail.com
In-Reply-To: <3f4fd2640808110859r148550d2h833dae05b9e6544e@mail.gmail.com>

```
On Mon, Aug 11, 2008 at 5:59 PM, Reece Dunn <msclrhd@googlemail.com> wrote:
> $ $(read yesno) && echo yes || echo no
> n
> yes
> $ $(read yesno) && echo yes || echo no
> y
> yes

funny, seeing these 2 cases I'm wondering why Bash is not complaining...

-- 
Francis

```

## Reece Dunn, 2008-08-11 16:26

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <3f4fd2640808110926w13104a08l687c8accc29e332@mail.gmail.com>
URL: https://gitlist.dev/e/3f4fd2640808110926w13104a08l687c8accc29e332%40mail.gmail.com
In-Reply-To: <38b2ab8a0808110923u21d543f0qbc9dee0f99c97311@mail.gmail.com>

```
2008/8/11 Francis Moreau <francis.moro@gmail.com>:
> On Mon, Aug 11, 2008 at 5:59 PM, Reece Dunn <msclrhd@googlemail.com> wrote:
>> $ $(read yesno) && echo yes || echo no
>> n
>> yes
>> $ $(read yesno) && echo yes || echo no
>> y
>> yes
>
> funny, seeing these 2 cases I'm wondering why Bash is not complaining...

I don't know; it could be an issue with cygwin.

I'll try it on a Linux box later and post the results then for comparison.

- Reece

```

## Francis Moreau, 2008-08-11 16:29

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <38b2ab8a0808110929i47f7e4dt5287d149d10afbaf@mail.gmail.com>
URL: https://gitlist.dev/e/38b2ab8a0808110929i47f7e4dt5287d149d10afbaf%40mail.gmail.com
In-Reply-To: <3f4fd2640808110926w13104a08l687c8accc29e332@mail.gmail.com>

```
On Mon, Aug 11, 2008 at 6:26 PM, Reece Dunn <msclrhd@googlemail.com> wrote:
> 2008/8/11 Francis Moreau <francis.moro@gmail.com>:
>> On Mon, Aug 11, 2008 at 5:59 PM, Reece Dunn <msclrhd@googlemail.com> wrote:
>>> $ $(read yesno) && echo yes || echo no
>>> n
>>> yes
>>> $ $(read yesno) && echo yes || echo no
>>> y
>>> yes
>>
>> funny, seeing these 2 cases I'm wondering why Bash is not complaining...
>
> I don't know; it could be an issue with cygwin.
>
> I'll try it on a Linux box later and post the results then for comparison.
>

I got the same result on Linux...

-- 
Francis

```

## Petr Baudis, 2008-08-11 16:49

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <20080811164945.GI32184@machine.or.cz>
URL: https://gitlist.dev/e/20080811164945.GI32184%40machine.or.cz
In-Reply-To: <3f4fd2640808110859r148550d2h833dae05b9e6544e@mail.gmail.com>

```
On Mon, Aug 11, 2008 at 04:59:32PM +0100, Reece Dunn wrote:
> >> On Mon, 11 Aug 2008, Francis Moreau wrote:
> >>>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
> 
> does not work as expected. Replacing this with
> 
>                case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esac
> 
> would work as intended, as Mikael has pointed out.

  Wouldn't it be more elegant to

	case "$(head -n 1)" in [Nn]*) exit 1 ;; esac

				Petr "Pasky" Baudis

```

## René Scharfe, 2008-08-11 17:01

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <48A0705B.3030107@lsrfire.ath.cx>
URL: https://gitlist.dev/e/48A0705B.3030107%40lsrfire.ath.cx
In-Reply-To: <20080811164945.GI32184@machine.or.cz>

```
Petr Baudis schrieb:
> On Mon, Aug 11, 2008 at 04:59:32PM +0100, Reece Dunn wrote:
>>>> On Mon, 11 Aug 2008, Francis Moreau wrote:
>>>>>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
>> does not work as expected. Replacing this with
>>
>>                case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esac
>>
>> would work as intended, as Mikael has pointed out.
> 
>   Wouldn't it be more elegant to
> 
> 	case "$(head -n 1)" in [Nn]*) exit 1 ;; esac

Only if head is a built-in, otherwise you fork needlessly.  Not that
this is a performance critical part, but I wouldn't call it "elegant".

What's wrong with the following variant, already used a few lines up in
the file?

	read yesno
	case "$yesno" in [Nn]*) exit 1 ;; esac

René

```

## Petr Baudis, 2008-08-11 17:05

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <20080811170515.GD10151@machine.or.cz>
URL: https://gitlist.dev/e/20080811170515.GD10151%40machine.or.cz
In-Reply-To: <48A0705B.3030107@lsrfire.ath.cx>

```
On Mon, Aug 11, 2008 at 07:01:15PM +0200, René Scharfe wrote:
> Petr Baudis schrieb:
> > On Mon, Aug 11, 2008 at 04:59:32PM +0100, Reece Dunn wrote:
> >>>> On Mon, 11 Aug 2008, Francis Moreau wrote:
> >>>>>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
> >> does not work as expected. Replacing this with
> >>
> >>                case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esac
> >>
> >> would work as intended, as Mikael has pointed out.
> > 
> >   Wouldn't it be more elegant to
> > 
> > 	case "$(head -n 1)" in [Nn]*) exit 1 ;; esac
> 
> Only if head is a built-in, otherwise you fork needlessly.  Not that
> this is a performance critical part, but I wouldn't call it "elegant".

Ok, exec head -n 1. ;) And yes, I know... I guess I've just spent too
much time perl-golfing lately.

> What's wrong with the following variant, already used a few lines up in
> the file?
> 
> 	read yesno
> 	case "$yesno" in [Nn]*) exit 1 ;; esac

Nothing wrong with this one, of course.

-- 
				Petr "Pasky" Baudis
The next generation of interesting software will be done
on the Macintosh, not the IBM PC.  -- Bill Gates

```

## Francis Moreau, 2008-08-11 17:38

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <38b2ab8a0808111038q686c9581pb277ab6d2229afd@mail.gmail.com>
URL: https://gitlist.dev/e/38b2ab8a0808111038q686c9581pb277ab6d2229afd%40mail.gmail.com
In-Reply-To: <48A06659.6010004@lsrfire.ath.cx>

```
On Mon, Aug 11, 2008 at 6:18 PM, René Scharfe
<rene.scharfe@lsrfire.ath.cx> wrote:
> Francis Moreau schrieb:
>> I found this in git bisect:
>>
>>               printf >&2 'Are you sure [Y/n]? '
>>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
>>
>> which looks very weird since read(1) returns a status and not the
>> string reads from std input.
>
> Good catch.  You need to press Ctrl-C in order to exit, answering "no"
> means the same as "yes" here -- not very nice.  Care to send a patch?
>

done.

-- 
Francis

```

## Junio C Hamano, 2008-08-11 18:59

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <7v7ianxtqv.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v7ianxtqv.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <48A0705B.3030107@lsrfire.ath.cx>

```
René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:

> Petr Baudis schrieb:
>> On Mon, Aug 11, 2008 at 04:59:32PM +0100, Reece Dunn wrote:
>>>>> On Mon, 11 Aug 2008, Francis Moreau wrote:
>>>>>>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
>>> does not work as expected. Replacing this with
>>>
>>>                case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esac
>>>
>>> would work as intended, as Mikael has pointed out.
>> 
>>   Wouldn't it be more elegant to
>> 
>> 	case "$(head -n 1)" in [Nn]*) exit 1 ;; esac
>
> Only if head is a built-in, otherwise you fork needlessly.  Not that
> this is a performance critical part, but I wouldn't call it "elegant".
>
> What's wrong with the following variant, already used a few lines up in
> the file?
>
> 	read yesno
> 	case "$yesno" in [Nn]*) exit 1 ;; esac

That's the right way to spell it.  Sorry, I must have been too tired
when I did this.

```

## Francis Moreau, 2008-08-11 19:47

Subject: Re: git-bisect: weird usage of read(1)
Message-ID: <38b2ab8a0808111247w4837a1bfn774b9c2e9b98d38b@mail.gmail.com>
URL: https://gitlist.dev/e/38b2ab8a0808111247w4837a1bfn774b9c2e9b98d38b%40mail.gmail.com
In-Reply-To: <7v7ianxtqv.fsf@gitster.siamese.dyndns.org>

```
On Mon, Aug 11, 2008 at 8:59 PM, Junio C Hamano <gitster@pobox.com> wrote:
> René Scharfe <rene.scharfe@lsrfire.ath.cx> writes:
>
>> Petr Baudis schrieb:
>>> On Mon, Aug 11, 2008 at 04:59:32PM +0100, Reece Dunn wrote:
>>>>>> On Mon, 11 Aug 2008, Francis Moreau wrote:
>>>>>>>               case "$(read yesno)" in [Nn]*) exit 1 ;; esac
>>>> does not work as expected. Replacing this with
>>>>
>>>>                case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esac
>>>>
>>>> would work as intended, as Mikael has pointed out.
>>>
>>>   Wouldn't it be more elegant to
>>>
>>>      case "$(head -n 1)" in [Nn]*) exit 1 ;; esac
>>
>> Only if head is a built-in, otherwise you fork needlessly.  Not that
>> this is a performance critical part, but I wouldn't call it "elegant".
>>
>> What's wrong with the following variant, already used a few lines up in
>> the file?
>>
>>       read yesno
>>       case "$yesno" in [Nn]*) exit 1 ;; esac
>
> That's the right way to spell it.  Sorry, I must have been too tired
> when I did this.
>
>
>

I sent a patch to fix that way already

Cheers.
-- 
Francis

```
