Path: utzoo!attcan!utgpu!jarvis.csri.toronto.edu!mailrus!tut.cis.ohio-state.edu!gem.mps.ohio-state.edu!rpi!rpi.edu!tale From: tale@pawl.rpi.edu (David C Lawrence) Newsgroups: comp.unix.questions Subject: Re: Strangeness in shell Message-ID: Date: 23 Jul 89 02:03:58 GMT References: <432@mccc.UUCP> <9700009@osiris.cso.uiuc.edu> Sender: usenet@rpi.edu Reply-To: tale@pawl.rpi.edu Lines: 42 In-reply-to: funk@osiris.cso.uiuc.edu's message of 22 Jul 89 09:17:00 GMT In <9700009@osiris.cso.uiuc.edu> funk@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@pawl.rpi.edu" "tale@itsgw.rpi.edu" "tale@rpitsmts.bitnet"))