Strangeness in shell

David C Lawrence tale at pawl.rpi.edu
Sun Jul 23 12:03:58 AEST 1989


In <9700009 at osiris.cso.uiuc.edu> funk at osiris.cso.uiuc.edu writes:
funk>  Ummm... I had always learned (obviously flawed) that the single
funk> quotes prevented expansion of ANYTHING....  Even if this is not
funk> the case, why does it behave differently in the two cases?  If
funk> you have no files ending in z , then why does it not return a
funk> null string for the '*z' version ?  What is its algoithm for
funk> determining when it is going to be literal and when it is going
funk> to expand???

The example in question is comparison of the following.
$ x='*z' ; echo $x
  vs
$ x='* z' ; echo $x

The original poster request that he be responded to in mail.  Since
the person who Mr Funk is responding to decided that he would post his
wonderful (!) explanation to the net instead, we have the potential to
see this discussed for much too long.  Hopefully this will prevent
that.

The Bourne shell is _not_ the C shell. Globbing (filename expansion)
is done differently.  If the shell (sh, not csh) cannot find an
expansion for the wildcards, it just leaves it.  Single quotes and
double quotes both prevent globbing.

Here are some more examples to clear it up a little:
$ x=*      # x is set to a list of non-dotfiles in the current directory.
$ x='*'    # x is set to just *
$ x="*"    # x is still set to just *

In the example that started all of this, x was set to the string which
was typed.  After variable substitution was done but before the
arguments were passed to echo, the shell did globbing on what the line
then looked like -- namely "echo *z" or "echo * z".  Since it couldn't
find filenames ending in z, it just passed *z as the argument.  In the
second case it expanded * to all the files in the directory and passed
them and z as arguments to echo.


Dave
--
 (setq mail '("tale at pawl.rpi.edu" "tale at itsgw.rpi.edu" "tale at rpitsmts.bitnet"))



More information about the Comp.unix.questions mailing list