[Fwd: Re: Send to a Listing]

felixs besteck455 at gmail.com
Wed Apr 17 20:45:11 UTC 2019


Thanks for your detailed comments and explanations. It will need a
second lecture with the Bash Reference Manual opened in another terminal
to fully understand the differences.

felixs

On Wed, Apr 17, 2019 at 08:28:56AM +1000, Cameron Simpson wrote:
> On 16Apr2019 18:40, felixs <besteck455 at gmail.com> wrote:
> > On Tue, Apr 16, 2019 at 09:52:57AM +1000, Cameron Simpson wrote:
> > > Globbing is used to construct command line arguments. But a
> > > redirection is
> > > not a command line parameter - it is only subject to parameter substitution
> > > - $blah.
> > 
> > Ok, got it. Globbing = filename expansion, as to the Bash Reference
> > Manual.
> 
> Yes. Expanding unquoted "*" etc to match multiple pathnames and putting
> those names in place of the pattern.
> 
> > Just to understand: the "${file}.out" in the variable assignment
> > Derek used is an example of a filename expansion, i.e. a special form of it,
> > because it does not expand to just one filename but a set of filenames,
> > that make up the directory?
> 
> No, this is parameter substitution (there's a section in the manual titled
> PARAMETER SUBTITUTION).  Parameters are shell variables like $file or
> ${file} or the other variations on ${.....} which can be used.  They are
> string expansions which come from shell variables, and they don't probe the
> filesystem to find out what files may be lying around.
> 
> By contrast, globbing aka filename expansion is a separate step in the shell
> command line construction which happens _after_ parameter subtitution. It
> recognised unquoted '*' and '[range]' sequences and probes the filesystem
> for matching paths.
> 
> Look:
> 
>  [~]fleet*> x='b*'
>  [~]fleet*> echo b*
>  bin bin-cs bin-darwin bin-local books bos build
>  [~]fleet*> echo $x
>  bin bin-cs bin-darwin bin-local books bos build
>  [~]fleet*> echo "$x"
>  b*
> 
> Here we set $b to "b*", then use it in various ways.
> 
> First, a literal "b*" to see what it expands to.
> 
> Second: by using $x to get the "b*"; because the $x is unquoted, _after_
> expanding $x, the resulting "b*" is used for globbing, and is expanded to
> the various "b"-starting things in my home directory.
> 
> Third: by using "$x" to get the "b*". After expansion, we get "b*" from $x.
> The globbing step still happens, but because the "*" is from the quoted
> section it is not expanded.
> 
> > (Or is it, therefore, an array?). I tend to say
> > "set", because in Python3 these braces would enclose a set, but maybe this
> > is misleading.
> 
> It is misleading. The ${} markers are just punctuation. Consider:
> 
>  x=a
>  echo ${x}a
>  echo ${xa}
> 
> The first echo accesses the "$x" variable. The second one accesses the "$xa"
> variable. If you want a Python comparison, thinnk of the {} markers in a
> format string:
> 
>  print("{x}a")
> 
> versus:
> 
>  print("{xa}")
> 
> except that in a format string the markers are mandatory. In the shell the
> convenience bare form "$x" is what is usually used. The {} markers lets you
> specificly delineate the start and end of the variable name, which is useful
> when the name is followed by letters which would otherwise be considered
> part of the name.
> 
> As an added bonus, once you are using ${....} you can put extra syntax
> inside the {} markers such as:
> 
>  echo ${x:-3}
> 
> which inserts the value of $x unless it is empty or unset, in which case it
> inserts "3".
> 
> Python isn't a good comparison lanuage here because as far as parameter
> substitution and globbing go, the shell is a kind of macro language: the
> concrete commands issued are from _after_ the macros (parameters and
> globbing) are expanded.
> 
> Python is not like that.
> 


More information about the Mutt-users mailing list