Re: [patch #10070] toggle invert flag when reading `!'

2021-05-26 Thread Dale R. Worley
>> >[[ ! 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: !(.pattern) can match . and .. if dotglob is enabled

2021-05-26 Thread Nora Platiel
Hello,

> This is behavior that changed more than ten years ago.

I thought it changed in this commit:
https://git.savannah.gnu.org/cgit/bash.git/commit/?id=ac50fbac377e32b98d2de396f016ea81e8ee9961
2014-02-26 -> 7.2 years ago
But yes, I know it's old stuff and I was not implying a regression, just 
mentioning it FYI.

> There was a relevant discussion back in January:
> https://lists.gnu.org/archive/html/bug-bash/2021-01/msg00240.html

Thanks, I did a search but I missed it.
It *is* relevant, because I think that @(?|.?) matching '.' is consistent with 
!(.foo) matching '.' and '..'

If you maintain that such behavior is correct, I have no problem with it.
I will just use [.]pattern even inside !(...) to get rid of '.' and '..'

The problem is, there is nothing in the docs that hints at such behavior.
I.e. that the pattern beginning with a literal dot may not match at all, but it 
still signal that '.' and '..' should be accepted in the final match.
The docs only talk about the requirement of '.' and  '..' to "be matched 
explicitly", which is vague and subject to interpretation, especially in the 
context of extended patterns.
I'm not the first person to complain about such wording.

> When dotglob is enabled, the shell's pattern matcher interprets an extglob
> pattern beginning with a literal `.' as specifying that files beginning
> with a `.' should match, so the negated pattern matches `.' and `..'.

Shouldn't this be the case with dotglob disabled?
And with dotglob enabled, the exclusion applies only to '.' and '..', instead 
of all dot-files.
If not, again the docs is wrong or incomplete.

dotglob enabled  -> '.' and  '..' require pattern beginning with literal dot
dotglob disabled -> all dot-files require pattern beginning with literal dot

I.e. my understanding is that every pattern starting with a literal dot should 
*not* be influenced by dotglob, because the literal dot calls off every 
exclusion.

Of course dotglob makes no difference here:
$ shopt -s dotglob; echo @(.*)
. .. .a
$ shopt -u dotglob; echo @(.*)
. .. .a

$ shopt -s dotglob; echo @(.?)
.. .a
$ shopt -u dotglob; echo @(.?)
.. .a

So why it does here?
$ shopt -s dotglob; echo @(.foo|*)
. .. .a b
$ shopt -u dotglob; echo @(.foo|*)
b

$ shopt -s dotglob; echo !(.foo)
. .. .a b
$ shopt -u dotglob; echo !(.foo)
b

Regards,
NP



Re: !(.pattern) can match . and .. if dotglob is enabled

2021-05-26 Thread Chet Ramey

On 5/25/21 8:58 PM, Nora Platiel wrote:


Bash Version: 5.1
Patch Level: 8
Release Status: release

Hello,

Repeat-By:
$ shopt -s dotglob extglob
$ echo !(.foo)
. .. .other files

The doc says: "The filenames '.' and '..' must always be matched explicitly, even if 
dotglob is set."


When dotglob is enabled, the shell's pattern matcher interprets an extglob
pattern beginning with a literal `.' as specifying that files beginning
with a `.' should match, so the negated pattern matches `.' and `..'.


Also the pattern !(.foo) didn't match . and .. before version 4.3.0.


This is behavior that changed more than ten years ago.

There was a relevant discussion back in January:

https://lists.gnu.org/archive/html/bug-bash/2021-01/msg00240.html

--
``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 `!'

2021-05-26 Thread felix
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