[comp.lang.c] Strangeness in shell

kemnitz@mitisft.Convergent.COM (Gregory Kemnitz) (07/19/89)

In article <432@mccc.UUCP> you write:
>
>If I assign a shell variable a value that contains an asterisk, the
>shell behaves strangely if there is a space adjacent to said asterisk. 
>For example,
>	x='*z'
>	echo ${x}
>produces
>	*z
>but 
>	x='* z'
>	echo ${x}
>produces
>	(a list of all the files in the current directory) z
>	
>What does the space have to do with this?
>
>Please mail and I'll summarize if there is interest.  Thanks.
>
>-- 
>Pete Holsberg -- Mercer College -- Trenton, NJ 08690
>...!rutgers!njin!princeton!njsmu!mccc!pjh

Try creating a couple of files in your directory called 

foo1z foo2z

Then you will see that in the first example, you have

x='*z'
echo ${x}

yields

foo1z foo2z

The shell tries to expand the star into filenames, and if it can
find any filenames matching the expression *z, it will substitute
them.  If it can't, it will keep *z as the value.  When you put a space,
(the delimiter the shell uses for arguments) you caused the expression to
be * by itself, which matches every filename by definition except dot files.

Sorry to post, the mailer blew up.

----------------------------------+--------------------------------------
Greg Kemnitz                      | Software without hardware is an idea.
kemnitz@Convergent.COM            | Hardware without software is a space heater.
				  |
                                  | --Unknown author