git-bisect: weird usage of read(1)
Hello
I found this in git bisect:
printf >&2 'Are you sure [Y/n]? '
case "$(read yesno)" in [Nn]*) exit 1 ;; esacwhich looks very weird since read(1) returns a status and not the string reads from std input.
Am I missing something ?
Thanks
Signature · 1 line
Francis
Quoted 7 lines · Francis Moreau
I found this in git bisect:
printf >&2 'Are you sure [Y/n]? ' case "$(read yesno)" in [Nn]*) exit 1 ;; esacwhich 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é
Quoted 12 lines · René Scharfe
Quoted 7 lines · Francis Moreau
I found this in git bisect:
printf >&2 'Are you sure [Y/n]? ' case "$(read yesno)" in [Nn]*) exit 1 ;; esacwhich 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.
Signature · 1 line
Francis
Hi,
Quoted 9 lines · Francis Moreau
I found this in git bisect:
printf >&2 'Are you sure [Y/n]? ' case "$(read yesno)" in [Nn]*) exit 1 ;; esacwhich 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
2008/8/11 Johannes Schindelin <[email protected]>:
Quoted 9 lines
Hi,
Quoted 5 lines · Francis Moreau
I found this in git bisect:
printf >&2 'Are you sure [Y/n]? ' case "$(read yesno)" in [Nn]*) exit 1 ;; esac
Quoted 6 lines
Quoted 4 lines
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?
Signature · 1 line
Mikael Magnusson
Hello
Quoted 12 lines · Johannes Schindelin
Hi,
Quoted 8 lines · Francis Moreau
I found this in git bisect:
printf >&2 'Are you sure [Y/n]? ' case "$(read yesno)" in [Nn]*) exit 1 ;; esacwhich 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 4 lines
Quoted 1 line
Am I missing something ?
Yes. "$()" does not return the status, but the output.
But what's the output in that case ?
Signature · 1 line
Francis
2008/8/11 Francis Moreau <[email protected]>:
Quoted 17 lines
Hello
Quoted 12 lines · Johannes Schindelin
Hi,
Quoted 8 lines · Francis Moreau
I found this in git bisect:
printf >&2 'Are you sure [Y/n]? ' case "$(read yesno)" in [Nn]*) exit 1 ;; esacwhich looks very weird since read(1) returns a status and not the string reads from std input.
Quoted 8 lines
sorry I should have said that there's a status but no output...
Quoted 4 lines
Quoted 1 line
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 1 line
Quoted 1 line
Quoted 1 line
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
Quoted 8 lines · Reece Dunn
Quoted 2 lines
Quoted 2 lines · Francis Moreau
Quoted 1 line
case "$(read yesno)" in [Nn]*) exit 1 ;; esacdoes not work as expected. Replacing this with
case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esacwould 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
Quoted 5 lines · Petr Baudis
Quoted 4 lines · Reece Dunn
Quoted 2 lines
Quoted 2 lines · Francis Moreau
Quoted 1 line
case "$(read yesno)" in [Nn]*) exit 1 ;; esacdoes not work as expected. Replacing this with
Quoted 7 lines
Quoted 3 lines
case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esacwould 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é
Quoted 8 lines · René Scharfe
Quoted 7 lines · Petr Baudis
Quoted 6 lines · Reece Dunn
Quoted 2 lines
Quoted 2 lines · Francis Moreau
Quoted 1 line
case "$(read yesno)" in [Nn]*) exit 1 ;; esacdoes not work as expected. Replacing this with
case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esac
Quoted 8 lines
Quoted 5 lines
Quoted 1 line
would work as intended, as Mikael has pointed out.
Wouldn't it be more elegant to
case "$(head -n 1)" in [Nn]*) exit 1 ;; esacOnly 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.
Quoted 5 lines
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.
Signature · 3 lines
Petr "Pasky" Baudis The next generation of interesting software will be done on the Macintosh, not the IBM PC. -- Bill Gates
Quoted 14 lines · René Scharfe
Quoted 5 lines · Petr Baudis
Quoted 4 lines · Reece Dunn
Quoted 2 lines
Quoted 2 lines · Francis Moreau
Quoted 1 line
case "$(read yesno)" in [Nn]*) exit 1 ;; esacdoes not work as expected. Replacing this with
Quoted 7 lines
Quoted 3 lines
case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esacwould work as intended, as Mikael has pointed out.
Wouldn't it be more elegant to
case "$(head -n 1)" in [Nn]*) exit 1 ;; esac
Quoted 8 lines
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.
Quoted 19 lines · Junio C Hamano
Quoted 17 lines · René Scharfe
Quoted 5 lines · Petr Baudis
Quoted 4 lines · Reece Dunn
Quoted 2 lines
Quoted 2 lines · Francis Moreau
Quoted 1 line
case "$(read yesno)" in [Nn]*) exit 1 ;; esacdoes not work as expected. Replacing this with
Quoted 7 lines
Quoted 3 lines
case "$(read yesno; echo $yesno)" in [Nn]*) exit 1 ;; esacwould work as intended, as Mikael has pointed out.
Wouldn't it be more elegant to
case "$(head -n 1)" in [Nn]*) exit 1 ;; esacOnly 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".
Quoted 11 lines
Quoted 5 lines
What's wrong with the following variant, already used a few lines up in the file?
read yesno case "$yesno" in [Nn]*) exit 1 ;; esacThat'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.
Signature · 1 line
Francis
Quoted 6 lines · Reece Dunn
$ $(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...
Signature · 1 line
Francis
2008/8/11 Francis Moreau <[email protected]>:
Quoted 9 lines · Reece Dunn
Quoted 6 lines
$ $(read yesno) && echo yes || echo no n yes $ $(read yesno) && echo yes || echo no y yesfunny, 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
Quoted 9 lines · Reece Dunn
2008/8/11 Francis Moreau <[email protected]>:
Quoted 8 lines · Reece Dunn
Quoted 6 lines
$ $(read yesno) && echo yes || echo no n yes $ $(read yesno) && echo yes || echo no y yes
Quoted 6 lines
Quoted 1 line
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...
Signature · 1 line
Francis