[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Glob star pattern does not match files beginning with a
From: |
Michael Convey |
Subject: |
Re: [Help-bash] Glob star pattern does not match files beginning with a period |
Date: |
Wed, 15 Jul 2015 17:49:50 -0700 |
On Wed, Jul 15, 2015 at 1:19 PM, Eric Blake <address@hidden> wrote:
> On 07/15/2015 01:58 PM, Michael Convey wrote:
>
> [top-posting on technical lists makes your responses harder to read]
>
Sorry, my mistake. I'll be more careful going forward.
>
> > I've done some more testing of this and found no difference between
> > ls -dl .[!.]?*
> > and
> > ls -dl .[!.]*
>
> Then you obviously didn't try it on a file named '.a'.
>
> >
> > In both cases the . directory does not appear in the output. Why doesn't
>
> >
>
>
> it
>
>
> appear in the second command? Does [!.] require a second character?
> Yes, [!.] requires a second character. The trailing ?* then requires a
> third character. So you have a difference of whether '.a' vs. '..a' vs.
> '...' get accepted, depending on whether you forbid a second dot vs.
> whether you require at least three characters
That now makes sense, thank you.
> , coupled with a desire to
> not list files twice through two different globs.
>
I see that now. I do have files listed twice. Looks like the following
really is the best way to go:
shopt -s dotglob
ls -dl *
I was trying to see if I could do it without changing that option. What are
the downsides to leaving the dotglob on by default?
>
> Both of these three-glob approaches can be used to obtain all file names
> that are not '.' or '..':
>
>
> ls -d * .[!.]* ..?*
>
> or:
>
> ls -d * .??* .[!.]
>
I assume you intended and asterisk at the end of the preceding line.
>
> but you still have to deal with the fact that unless nullglob is
> enabled to eliminate a glob that has no matches, you are then passing
> unexpanded globs to ls that may result in listing a valid file name
> twice, or in ls reporting an error about a file not found.
>
Interesting. When I execute each of the following commands in an empty
directory, i get an error:
ls -d .??*
ls -d ..?*
ls -d .[!.]*
However, if I set nullglob, each of those commands outputs '.' -- which
doesn't seem right.
> There is no two-glob pattern that can cover all file names except for .
> and .., unless you resort to bash's extended globs (at which point, you
> might as well do it in a single glob that uses alternation).
>
> By alternation, do you mean something like the following:
ls -dl * -o .[!.]* -o ..?*
This seems to work perfectly with no duplicate output and dotglob and
nullglob unset.
However, the following produced an error:
ls -dl {*|.[!.]*|..?*}
I also tried [...], but that errored as well. Is there another fairly
simple way to perform alternation without using extended globs?
- [Help-bash] Glob star pattern does not match files beginning with a period, David Niklas, 2015/07/13
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Michael Convey, 2015/07/13
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Evan Gates, 2015/07/13
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Michael Convey, 2015/07/13
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Michael Convey, 2015/07/15
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Greg Wooledge, 2015/07/15
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Eric Blake, 2015/07/15
- Re: [Help-bash] Glob star pattern does not match files beginning with a period,
Michael Convey <=
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Peter West, 2015/07/16
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Greg Wooledge, 2015/07/16
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Eric Blake, 2015/07/16
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Michael Convey, 2015/07/16
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Eric Blake, 2015/07/16
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Greg Wooledge, 2015/07/17
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Stephane Chazelas, 2015/07/21
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Michael Convey, 2015/07/24
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Greg Wooledge, 2015/07/24
- Re: [Help-bash] Glob star pattern does not match files beginning with a period, Matthew Cengia, 2015/07/24