Re: [patch #10070] toggle invert flag when reading `!'
Op 24-05-21 om 17:47 schreef Chet Ramey: On 5/22/21 2:45 PM, Vincent Menegaux wrote: Previously, these commands: [[ ! 1 -eq 1 ]]; echo $? [[ ! ! 1 -eq 1 ]]; echo $? would both result in `1', since parsing `!' set CMD_INVERT_RETURN instead of toggling it. Interestingly, ksh93 produces the same result as bash. I agree that it's more intuitive to toggle it. Also interesting is that '!' as an argument to the simple 'test'/'[' command does work as expected (on both bash and ksh93): 'test ! ! 1 -eq 1' and '[ ! ! 1 -eq 1 ]' return 0/true. Even the man page for [[ is identical for bash and ksh93: | ! expression | True if expression is false. This suggests it's supposed to be a logical negation operator, i.e. '!' is implicitly documented to negate another '!'. Bolsky & Korn's 1995 ksh book, p. 167, is slightly more explicit about it: "! test-expression. Logical negation of test-expression." I also note that multiple '!' negators in '[[' work as expected on mksh, yash and zsh. So, it seems clear that this is an actual bug in bash and ksh. I see it's been fixed in the bash devel tree now. I'll fix it in ksh 93u+m. -- || modernish -- harness the shell || https://github.com/modernish/modernish || || KornShell lives! || https://github.com/ksh93/ksh
Re: [patch #10070] toggle invert flag when reading `!'
On Mai 27 2021, Chet Ramey wrote: > You can argue that it's not clear enough that it allows multiple `!' > operators, Not from my reading of the description. It largely follows the POSIX gammar by only putting a single [!] into the pipeline syntax. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Re: [patch #10070] toggle invert flag when reading `!'
On 5/27/21 11:43 AM, Andreas Schwab wrote: True, but bash accepts it. The manual doesn't document that extension, though. The bash manual documents the bash implementation. You can argue that it's not clear enough that it allows multiple `!' operators, but it does not say that it uses the POSIX grammar as a base and documents deviations. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
Re: [patch #10070] toggle invert flag when reading `!'
On Mai 27 2021, Alex fxmbsw7 Ratchev wrote: > why doesnt it accept ! after | Because either side of | cannot be a pipeline. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Re: [patch #10070] toggle invert flag when reading `!'
On Mai 27 2021, Alex fxmbsw7 Ratchev wrote: > thought it would be useful, especially with PIPESTATUS You can always use a brace group. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Re: [patch #10070] toggle invert flag when reading `!'
thought it would be useful, especially with PIPESTATUS On Thu, May 27, 2021, 17:49 Greg Wooledge wrote: > On Thu, May 27, 2021 at 05:46:41PM +0200, Alex fxmbsw7 Ratchev wrote: > > why doesnt it accept ! after | > > Because ! negates a pipeline, not a simple command inside a pipeline. > >
Re: [patch #10070] toggle invert flag when reading `!'
On Thu, May 27, 2021 at 05:46:41PM +0200, Alex fxmbsw7 Ratchev wrote: > why doesnt it accept ! after | Because ! negates a pipeline, not a simple command inside a pipeline.
Re: [patch #10070] toggle invert flag when reading `!'
why doesnt it accept ! after | On Thu, May 27, 2021, 17:38 Chet Ramey wrote: > On 5/27/21 11:20 AM, Andreas Schwab wrote: > > On Mai 27 2021, Chet Ramey wrote: > > > >> On 5/26/21 9:55 PM, Dale R. Worley wrote: > >> > $ ! ! [ 1 -eq 1 ]; echo $? > 0 > >>> That last one isn't defined by the manual page. I'm surprised you > don't > >>> get a syntax error. > >> > >> It's clearly valid. > > > > According to the POSIX grammar, a pipeline can only be a pipe_sequence > > optionally preceded by a single Bang. If you want another Bang the > > pipe_sequnce needs to be either a subshell or a brace_group. > > True, but bash accepts it. (So do ksh and mksh; dash and yash do not.) > > > -- > ``The lyf so short, the craft so long to lerne.'' - Chaucer > ``Ars longa, vita brevis'' - Hippocrates > Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/ > >
Re: [patch #10070] toggle invert flag when reading `!'
On Mai 27 2021, Chet Ramey wrote: > On 5/27/21 11:20 AM, Andreas Schwab wrote: >> On Mai 27 2021, Chet Ramey wrote: >> >>> On 5/26/21 9:55 PM, Dale R. Worley wrote: >>> > $ ! ! [ 1 -eq 1 ]; echo $? > 0 That last one isn't defined by the manual page. I'm surprised you don't get a syntax error. >>> >>> It's clearly valid. >> According to the POSIX grammar, a pipeline can only be a pipe_sequence >> optionally preceded by a single Bang. If you want another Bang the >> pipe_sequnce needs to be either a subshell or a brace_group. > > True, but bash accepts it. The manual doesn't document that extension, though. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Re: [patch #10070] toggle invert flag when reading `!'
On 5/27/21 11:20 AM, Andreas Schwab wrote: On Mai 27 2021, Chet Ramey wrote: On 5/26/21 9:55 PM, Dale R. Worley wrote: $ ! ! [ 1 -eq 1 ]; echo $? 0 That last one isn't defined by the manual page. I'm surprised you don't get a syntax error. It's clearly valid. According to the POSIX grammar, a pipeline can only be a pipe_sequence optionally preceded by a single Bang. If you want another Bang the pipe_sequnce needs to be either a subshell or a brace_group. True, but bash accepts it. (So do ksh and mksh; dash and yash do not.) -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
Re: [patch #10070] toggle invert flag when reading `!'
On Mai 27 2021, Chet Ramey wrote: > On 5/26/21 9:55 PM, Dale R. Worley wrote: > >>>$ ! ! [ 1 -eq 1 ]; echo $? >>>0 >> That last one isn't defined by the manual page. I'm surprised you don't >> get a syntax error. > > It's clearly valid. According to the POSIX grammar, a pipeline can only be a pipe_sequence optionally preceded by a single Bang. If you want another Bang the pipe_sequnce needs to be either a subshell or a brace_group. Andreas. -- Andreas Schwab, sch...@linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
Re: [patch #10070] toggle invert flag when reading `!'
On 5/26/21 9:55 PM, Dale R. Worley wrote: $ ! ! [ 1 -eq 1 ]; echo $? 0 That last one isn't defined by the manual page. I'm surprised you don't get a syntax error. It's clearly valid. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/
Re: [patch #10070] toggle invert flag when reading `!'
>> >[[ ! 1 -eq 1 ]]; echo $? >> >[[ ! ! 1 -eq 1 ]]; echo $? >> > >> > would both result in `1', since parsing `!' set CMD_INVERT_RETURN >> > instead of toggling it. Definitely, the section of the man page for "[[" says that "!" is a negation operator, so "! ! foo" must yield the same results as "foo". > I will try this as: > > $ [ 1 -eq 1 ]; echo $? > 0 > $ ! [ 1 -eq 1 ]; echo $? > 1 > $ ! ! [ 1 -eq 1 ]; echo $? > 0 That last one isn't defined by the manual page. I'm surprised you don't get a syntax error. Pipelines A pipeline is a sequence of one or more commands separated by one of the control operators | or |&. The format for a pipeline is: [time [-p]] [ ! ] command [ [|||&] command2 ... ] Dale
Re: [patch #10070] toggle invert flag when reading `!'
On Mon, May 24, 2021 at 11:47:32AM -0400, Chet Ramey wrote: > On 5/22/21 2:45 PM, Vincent Menegaux wrote: > > > Details: > > > > Previously, these commands: > > > >[[ ! 1 -eq 1 ]]; echo $? > >[[ ! ! 1 -eq 1 ]]; echo $? > > > > would both result in `1', since parsing `!' set CMD_INVERT_RETURN > > instead of toggling it. I will try this as: $ [ 1 -eq 1 ]; echo $? 0 $ ! [ 1 -eq 1 ]; echo $? 1 $ ! ! [ 1 -eq 1 ]; echo $? 0 -- Félix Hauri -- http://www.f-hauri.ch
Re: [patch #10070] toggle invert flag when reading `!'
On 5/22/21 2:45 PM, Vincent Menegaux wrote: Details: Previously, these commands: [[ ! 1 -eq 1 ]]; echo $? [[ ! ! 1 -eq 1 ]]; echo $? would both result in `1', since parsing `!' set CMD_INVERT_RETURN instead of toggling it. Interestingly, ksh93 produces the same result as bash. I agree that it's more intuitive to toggle it. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRUc...@case.eduhttp://tiswww.cwru.edu/~chet/