Re: git-bisect: weird usage of read(1)
- Date: Mon, 11 Aug 2008 16:59:32 +0100
- From: "Reece Dunn" <msclrhd@xxxxxxxxxxxxxx>
- Subject: Re: git-bisect: weird usage of read(1)
2008/8/11 Francis Moreau <francis.moro@xxxxxxxxx>:
> Hello
>
> On Mon, Aug 11, 2008 at 4:15 PM, Johannes Schindelin
> <Johannes.Schindelin@xxxxxx> 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
--
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html