Strangeness in shell

fawcett fawcett at steven.COM
Sat Jul 22 03:26:45 AEST 1989


>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

The problem here is that the "set" of x stripped off the single quotes.
This left only the *, which matches all occourances of one or more
characters.  Why it looked in your directory for these files I don't know.
The fact that the *z echoed simply means that you don't have any files in
your directory that end in the letter z.

Try doing a ls *.  This will list every file in your directory and every
file in any subdirectory you have.  The ls will only go down one level,
since a ls <dir> will only go down one level.

If you wanted to echo the string *, either say echo '*', or try
saying 

set x='* a'
echo "${x}"

this will echo "* a" (without the quotes, of course).  Simularly, saying

set x='*'
echo "${x}"

will echo a "*" (without the quotes, of course).

Hope this helps.


John W. Fawcett             -----   -----   -----    -----    -----    ------
Software Engineer          /          /    /        /    /   /    /   /     /
Sierra Geophysics, Inc .   -----     /    /---     /-----   /-----   /-----/
P.O. Box 3886                  /    /    /        /   \    /  \     /     /
Seattle, Wa.  98124      -----   -----   -----   /     \  /    \   /     /

Voice: (206) 822-5200    uucp: ..!uw-beaver!sumax!quick!ole!steven!fawcett



More information about the Comp.unix.questions mailing list