git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* git-bisect: weird usage of read(1)
@ 2008-08-11 13:57 Francis Moreau
  2008-08-11 14:15 ` Johannes Schindelin
  2008-08-11 16:18 ` René Scharfe
  0 siblings, 2 replies; 16+ messages in thread
From: Francis Moreau @ 2008-08-11 13:57 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* git-bisect: weird usage of read(1)
@ 2008-08-11 14:00 Francis Moreau
  0 siblings, 0 replies; 16+ messages in thread
From: Francis Moreau @ 2008-08-11 14:00 UTC (permalink / raw)
  To: git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 13:57 git-bisect: weird usage of read(1) Francis Moreau
@ 2008-08-11 14:15 ` Johannes Schindelin
  2008-08-11 14:16   ` Mikael Magnusson
  2008-08-11 14:18   ` Francis Moreau
  2008-08-11 16:18 ` René Scharfe
  1 sibling, 2 replies; 16+ messages in thread
From: Johannes Schindelin @ 2008-08-11 14:15 UTC (permalink / raw)
  To: Francis Moreau; +Cc: git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 14:15 ` Johannes Schindelin
@ 2008-08-11 14:16   ` Mikael Magnusson
  2008-08-11 14:18   ` Francis Moreau
  1 sibling, 0 replies; 16+ messages in thread
From: Mikael Magnusson @ 2008-08-11 14:16 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: Francis Moreau, git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 14:15 ` Johannes Schindelin
  2008-08-11 14:16   ` Mikael Magnusson
@ 2008-08-11 14:18   ` Francis Moreau
  2008-08-11 15:59     ` Reece Dunn
  1 sibling, 1 reply; 16+ messages in thread
From: Francis Moreau @ 2008-08-11 14:18 UTC (permalink / raw)
  To: Johannes Schindelin; +Cc: git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 14:18   ` Francis Moreau
@ 2008-08-11 15:59     ` Reece Dunn
  2008-08-11 16:23       ` Francis Moreau
  2008-08-11 16:49       ` Petr Baudis
  0 siblings, 2 replies; 16+ messages in thread
From: Reece Dunn @ 2008-08-11 15:59 UTC (permalink / raw)
  To: Francis Moreau; +Cc: Johannes Schindelin, git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 13:57 git-bisect: weird usage of read(1) Francis Moreau
  2008-08-11 14:15 ` Johannes Schindelin
@ 2008-08-11 16:18 ` René Scharfe
  2008-08-11 17:38   ` Francis Moreau
  1 sibling, 1 reply; 16+ messages in thread
From: René Scharfe @ 2008-08-11 16:18 UTC (permalink / raw)
  To: Francis Moreau; +Cc: git

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é

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 15:59     ` Reece Dunn
@ 2008-08-11 16:23       ` Francis Moreau
  2008-08-11 16:26         ` Reece Dunn
  2008-08-11 16:49       ` Petr Baudis
  1 sibling, 1 reply; 16+ messages in thread
From: Francis Moreau @ 2008-08-11 16:23 UTC (permalink / raw)
  To: Reece Dunn; +Cc: Johannes Schindelin, git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 16:23       ` Francis Moreau
@ 2008-08-11 16:26         ` Reece Dunn
  2008-08-11 16:29           ` Francis Moreau
  0 siblings, 1 reply; 16+ messages in thread
From: Reece Dunn @ 2008-08-11 16:26 UTC (permalink / raw)
  To: Francis Moreau; +Cc: Johannes Schindelin, git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 16:26         ` Reece Dunn
@ 2008-08-11 16:29           ` Francis Moreau
  0 siblings, 0 replies; 16+ messages in thread
From: Francis Moreau @ 2008-08-11 16:29 UTC (permalink / raw)
  To: Reece Dunn; +Cc: Johannes Schindelin, git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 15:59     ` Reece Dunn
  2008-08-11 16:23       ` Francis Moreau
@ 2008-08-11 16:49       ` Petr Baudis
  2008-08-11 17:01         ` René Scharfe
  1 sibling, 1 reply; 16+ messages in thread
From: Petr Baudis @ 2008-08-11 16:49 UTC (permalink / raw)
  To: Reece Dunn; +Cc: Francis Moreau, Johannes Schindelin, git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 16:49       ` Petr Baudis
@ 2008-08-11 17:01         ` René Scharfe
  2008-08-11 17:05           ` Petr Baudis
  2008-08-11 18:59           ` Junio C Hamano
  0 siblings, 2 replies; 16+ messages in thread
From: René Scharfe @ 2008-08-11 17:01 UTC (permalink / raw)
  To: Petr Baudis; +Cc: Reece Dunn, Francis Moreau, Johannes Schindelin, git

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é

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 17:01         ` René Scharfe
@ 2008-08-11 17:05           ` Petr Baudis
  2008-08-11 18:59           ` Junio C Hamano
  1 sibling, 0 replies; 16+ messages in thread
From: Petr Baudis @ 2008-08-11 17:05 UTC (permalink / raw)
  To: René Scharfe; +Cc: Reece Dunn, Francis Moreau, Johannes Schindelin, git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 16:18 ` René Scharfe
@ 2008-08-11 17:38   ` Francis Moreau
  0 siblings, 0 replies; 16+ messages in thread
From: Francis Moreau @ 2008-08-11 17:38 UTC (permalink / raw)
  To: René Scharfe; +Cc: git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 17:01         ` René Scharfe
  2008-08-11 17:05           ` Petr Baudis
@ 2008-08-11 18:59           ` Junio C Hamano
  2008-08-11 19:47             ` Francis Moreau
  1 sibling, 1 reply; 16+ messages in thread
From: Junio C Hamano @ 2008-08-11 18:59 UTC (permalink / raw)
  To: René Scharfe
  Cc: Petr Baudis, Reece Dunn, Francis Moreau, Johannes Schindelin, git

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.

^ permalink raw reply	[flat|nested] 16+ messages in thread

* Re: git-bisect: weird usage of read(1)
  2008-08-11 18:59           ` Junio C Hamano
@ 2008-08-11 19:47             ` Francis Moreau
  0 siblings, 0 replies; 16+ messages in thread
From: Francis Moreau @ 2008-08-11 19:47 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: René Scharfe, Petr Baudis, Reece Dunn, Johannes Schindelin,
	git

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

^ permalink raw reply	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2008-08-11 19:48 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-08-11 13:57 git-bisect: weird usage of read(1) Francis Moreau
2008-08-11 14:15 ` Johannes Schindelin
2008-08-11 14:16   ` Mikael Magnusson
2008-08-11 14:18   ` Francis Moreau
2008-08-11 15:59     ` Reece Dunn
2008-08-11 16:23       ` Francis Moreau
2008-08-11 16:26         ` Reece Dunn
2008-08-11 16:29           ` Francis Moreau
2008-08-11 16:49       ` Petr Baudis
2008-08-11 17:01         ` René Scharfe
2008-08-11 17:05           ` Petr Baudis
2008-08-11 18:59           ` Junio C Hamano
2008-08-11 19:47             ` Francis Moreau
2008-08-11 16:18 ` René Scharfe
2008-08-11 17:38   ` Francis Moreau
  -- strict thread matches above, loose matches on Subject: below --
2008-08-11 14:00 Francis Moreau

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).