[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: docs incorrectly mention pattern matching works like pathname expans

From: Greg Wooledge
Subject: Re: docs incorrectly mention pattern matching works like pathname expansion
Date: Fri, 16 Mar 2018 08:24:32 -0400
User-agent: NeoMutt/20170113 (1.7.2)

On Fri, Mar 16, 2018 at 10:04:07AM +0000, Stormy wrote:
> Thanks for the confirmation regarding the need to write code. and also about 
> 'cd' 'ls', yeah, it's what I sort of mean, bash does when passing args to 
> them, but there is no other way to 'access' this type of parsing..

You are still quite confused.  Globbing (filename expansion) is done by
bash when a glob is evaluated in several different contexts.  There are
ways to use this.  Real ways.  This is not just esoteric bullshit.

Context #1 is when the glob is part of an argument list.  I gave this
example previously in this thread:

  echo *

Do you not understand how this works?  Bash expands the glob (*) into
a list of filename argument-words.  Each argument is passed to echo
as part of echo's argv[] array.  Then, echo prints each of them, because
that's what echo does.

Passing an argument list of unbounded size to a command may run into
system-specific length limits.  See
<https://www.in-ulm.de/~mascheck/various/argmax/> for details.

Context #2 is when the glob is part of an array assignment, like this:


In this case, the glob is expanded into a list of filenames, which are
then used as the argument-words to stuff into the array.  The result
is an array containing all of the filenames that matched the glob, one
filename per array element, one array element per filename.

Since this is not a command's argv[] there is no limit on the length,
other than however much memory bash can allocate.

Context #3 is when the glob is one of the words following
"for varname in".

  for f in *

The glob is expanded to a list of filenames which is stored internally
and used as the iteration list of the for loop.  You don't have direct
access to the complete list of filenames at any point (use an array if
that's what you want), but you do get access to one filename at a time
as the for loop iterates.  Each filename becomes the content of the
variable named "f", one by one.

Again, there is no limit on the length of this internal filename list,
other than the amount of memory bash can allocate.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]