git-bisect: weird usage of read(1)

13 messages, 6 authors, 2016-06-15 · open the first message on its own page

git-bisect: weird usage of read(1)

From: Francis Moreau <hidden>
Date: 2016-06-15 22:45:08

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

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

From: Johannes Schindelin <hidden>
Date: 2016-06-15 22:45:08

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

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

From: Mikael Magnusson <hidden>
Date: 2016-06-15 22:45:08

2008/8/11 Johannes Schindelin [off-list ref]:
Hi,

On Mon, 11 Aug 2008, Francis Moreau wrote:
quoted
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

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

From: Francis Moreau <hidden>
Date: 2016-06-15 22:45:08

Hello

On Mon, Aug 11, 2008 at 4:15 PM, Johannes Schindelin
[off-list ref] wrote:
Hi,

On Mon, 11 Aug 2008, Francis Moreau wrote:
quoted
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...
quoted
Am I missing something ?
Yes.  "$()" does not return the status, but the output.
But what's the output in that case ?

-- 
Francis

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

From: Reece Dunn <hidden>
Date: 2016-06-15 22:45:08

2008/8/11 Francis Moreau [off-list ref]:
Hello

On Mon, Aug 11, 2008 at 4:15 PM, Johannes Schindelin
[off-list ref] wrote:
quoted
Hi,

On Mon, 11 Aug 2008, Francis Moreau wrote:
quoted
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...
quoted
quoted
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
quoted
quoted
              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

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

From: René Scharfe <hidden>
Date: 2016-06-15 22:45:08

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é

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

From: Francis Moreau <hidden>
Date: 2016-06-15 22:45:08

On Mon, Aug 11, 2008 at 5:59 PM, Reece Dunn [off-list ref] 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

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

From: Reece Dunn <hidden>
Date: 2016-06-15 22:45:08

2008/8/11 Francis Moreau [off-list ref]:
On Mon, Aug 11, 2008 at 5:59 PM, Reece Dunn [off-list ref] wrote:
quoted
$ $(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

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

From: Francis Moreau <hidden>
Date: 2016-06-15 22:45:08

On Mon, Aug 11, 2008 at 6:26 PM, Reece Dunn [off-list ref] wrote:
2008/8/11 Francis Moreau [off-list ref]:
quoted
On Mon, Aug 11, 2008 at 5:59 PM, Reece Dunn [off-list ref] wrote:
quoted
$ $(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

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

From: Petr Baudis <hidden>
Date: 2016-06-15 22:45:08

On Mon, Aug 11, 2008 at 04:59:32PM +0100, Reece Dunn wrote:
quoted
quoted
On Mon, 11 Aug 2008, Francis Moreau wrote:
quoted
              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

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

From: René Scharfe <hidden>
Date: 2016-06-15 22:45:08

Petr Baudis schrieb:
On Mon, Aug 11, 2008 at 04:59:32PM +0100, Reece Dunn wrote:
quoted
quoted
quoted
On Mon, 11 Aug 2008, Francis Moreau wrote:
quoted
              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é

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

From: Petr Baudis <hidden>
Date: 2016-06-15 22:45:08

On Mon, Aug 11, 2008 at 07:01:15PM +0200, René Scharfe wrote:
Petr Baudis schrieb:
quoted
On Mon, Aug 11, 2008 at 04:59:32PM +0100, Reece Dunn wrote:
quoted
quoted
quoted
On Mon, 11 Aug 2008, Francis Moreau wrote:
quoted
              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

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

From: Francis Moreau <hidden>
Date: 2016-06-15 22:45:08

On Mon, Aug 11, 2008 at 6:18 PM, René Scharfe
[off-list ref] wrote:
Francis Moreau schrieb:
quoted
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
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help