From: "13mb80000-HallM(DR3132)37x10" <marcus@bighorn.dr.lucent.com>
To: cygwin@sourceware.cygnus.com
Subject: Re: How do I list subdirectories?
Date: Wed, 25 Aug 1999 13:41:00 -0000 [thread overview]
Message-ID: <199908252041.OAA07680@chorus> (raw)
> Nice try but
> ls -F | egrep .*\/
> doesn't work.
> I agree that it ought to. I don't understand why it
> doesn't.
For a hint, try the command:
echo .*\/
and you will see that the shell globs the argument. Depending on the contents
of the directory, you will get something like ./ ../ as output from the echo.
So, the command:
ls -F | egrep .*\/
is the same as saying
ls -F | egrep ./ ../
Which certainly isn't what you want.
Try
ls -F | egrep '.*\/'
> However Kim Poulsen found a command that does work:
> ls -F | egrep \/
>
> It seems that this is a question on pattern matching.
> It seems to me that a directory which is mached by:
> \/
> should also be matched by
> *\/
> and
> .*\/
Egrep works with regular expressions, shell works with glob expressions.
In regular expressions, the * means zero or more of whatever preceeded the
*. Thus, in the second case, since there was nothing preceeding the *,
it really doesn't make sense as a regular expression. If you pass that
to egrep (remember to quote it to protect it from the shell) egrep reports
a syntax error.
So, when passed to egrep, the first pattern recognizes a slash (I still
don't understand the need to escape the slash, since it has no particular
meaning to egrep.) The second pattern is a syntax error, and the third
pattern matches anything (or nothing) and then a slash.
As shell glob expressions, the first pattern doesn't contain any glob
characters and so it would be passed as a slash (the shell does remove
the escape backslash). The second pattern would match any path that can
be constructed with anything (the *) followed by a slash. This gives
you all of the directories within the current directory (at least those
that don't start with a ., because the shell doesn't expand * to include
those files). The third expression would match any path that can be
constructed with a leading ., then anything, then a slash. So, using
the shell instead of egrep, we can come very close to the desired behavior
with the command:
echo */ .*/
When the shell processes the arguments, the first argument will be replaced
with all directories that do not begin with a '.' and the second will be
replaced with all directories that do begin with a '.'. The only problem
here is that if the pattern doesn't match anything, then it will be left
there and not expanded. So, if you have a basically empty directory, this
will produce
*/ ./ ../
since the first argument is not expanded (nothing matches it) and the second
matches the current and parent directories. To eliminate this bother, we
can use ls instead and throw away the error, so the command:
ls -d */ .*/ 2>/dev/null
should show all the directories within the current directory.
marcus hall
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
WARNING: multiple messages have this Message-ID
From: "13mb80000-HallM(DR3132)37x10" <marcus@bighorn.dr.lucent.com>
To: cygwin@sourceware.cygnus.com
Subject: Re: How do I list subdirectories?
Date: Tue, 31 Aug 1999 23:49:00 -0000 [thread overview]
Message-ID: <199908252041.OAA07680@chorus> (raw)
Message-ID: <19990831234900.br6qz0LPwlBk9JeQZkmbB18Oc54H9k_T0rg80jqCoy4@z> (raw)
> Nice try but
> ls -F | egrep .*\/
> doesn't work.
> I agree that it ought to. I don't understand why it
> doesn't.
For a hint, try the command:
echo .*\/
and you will see that the shell globs the argument. Depending on the contents
of the directory, you will get something like ./ ../ as output from the echo.
So, the command:
ls -F | egrep .*\/
is the same as saying
ls -F | egrep ./ ../
Which certainly isn't what you want.
Try
ls -F | egrep '.*\/'
> However Kim Poulsen found a command that does work:
> ls -F | egrep \/
>
> It seems that this is a question on pattern matching.
> It seems to me that a directory which is mached by:
> \/
> should also be matched by
> *\/
> and
> .*\/
Egrep works with regular expressions, shell works with glob expressions.
In regular expressions, the * means zero or more of whatever preceeded the
*. Thus, in the second case, since there was nothing preceeding the *,
it really doesn't make sense as a regular expression. If you pass that
to egrep (remember to quote it to protect it from the shell) egrep reports
a syntax error.
So, when passed to egrep, the first pattern recognizes a slash (I still
don't understand the need to escape the slash, since it has no particular
meaning to egrep.) The second pattern is a syntax error, and the third
pattern matches anything (or nothing) and then a slash.
As shell glob expressions, the first pattern doesn't contain any glob
characters and so it would be passed as a slash (the shell does remove
the escape backslash). The second pattern would match any path that can
be constructed with anything (the *) followed by a slash. This gives
you all of the directories within the current directory (at least those
that don't start with a ., because the shell doesn't expand * to include
those files). The third expression would match any path that can be
constructed with a leading ., then anything, then a slash. So, using
the shell instead of egrep, we can come very close to the desired behavior
with the command:
echo */ .*/
When the shell processes the arguments, the first argument will be replaced
with all directories that do not begin with a '.' and the second will be
replaced with all directories that do begin with a '.'. The only problem
here is that if the pattern doesn't match anything, then it will be left
there and not expanded. So, if you have a basically empty directory, this
will produce
*/ ./ ../
since the first argument is not expanded (nothing matches it) and the second
matches the current and parent directories. To eliminate this bother, we
can use ls instead and throw away the error, so the command:
ls -d */ .*/ 2>/dev/null
should show all the directories within the current directory.
marcus hall
--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com
next reply other threads:[~1999-08-25 13:41 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
1999-08-25 13:41 13mb80000-HallM(DR3132)37x10 [this message]
1999-08-31 23:49 ` 13mb80000-HallM(DR3132)37x10
-- strict thread matches above, loose matches on Subject: below --
1999-08-25 14:23 13mb80000-HallM(DR3132)37x10
1999-08-31 23:49 ` 13mb80000-HallM(DR3132)37x10
1999-08-25 10:04 John Wiersba
1999-08-25 12:07 ` Joshua Rosen
1999-08-31 23:49 ` Joshua Rosen
1999-08-31 23:49 ` John Wiersba
1999-08-25 8:06 John Wiersba
1999-08-31 23:49 ` John Wiersba
1999-08-25 6:44 Earnie Boyd
1999-08-31 23:49 ` Earnie Boyd
1999-08-25 6:10 Clark Sims
1999-08-25 7:36 ` Keith Starsmeare
1999-08-31 23:49 ` Keith Starsmeare
1999-08-25 9:26 ` Joshua Rosen
1999-08-31 23:49 ` Joshua Rosen
1999-08-25 18:15 ` Ajit George
1999-08-26 12:25 ` Josh Baudhuin
1999-08-31 23:49 ` Josh Baudhuin
1999-08-31 23:49 ` Ajit George
1999-08-31 23:49 ` Clark Sims
1999-08-25 5:24 Earnie Boyd
1999-08-31 23:49 ` Earnie Boyd
1999-08-25 5:13 Clark Sims
1999-08-25 5:20 ` Kim Poulsen
1999-08-31 23:49 ` Kim Poulsen
1999-08-31 23:49 ` Clark Sims
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=199908252041.OAA07680@chorus \
--to=marcus@bighorn.dr.lucent.com \
--cc=cygwin@sourceware.cygnus.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).