C-Shell weirdness (count of words in a variable)

Greg Woods woods at hao.UUCP
Thu Mar 27 08:28:09 AEST 1986


> > set hosed
> > echo $#hosed
> > 
> > THEN you will get 0.
> 
> Sorry, I tried the example that is supposed to yield zero and I got one
> instead.
> 
> The answer is that you can't have a variable with 0 words at all.
> This fact I find counter-intuitive and undocumented

    I stand corrected. It seems that $#var is either an error or a positive
integer. Counterintuitive is debatable, however; a variable with no words
is kind of like saying something that is nothing. The only exception
I am aware of to this is that $#argv CAN be zero if it occurs in a shell
which was given no arguments (which includes your login shell; try it).
THIS is what is counter-intutive to ME, that argv behaves differently than
all other variables in this respect.

> I still can't figure out where
> the documentation says that if a variable name in an if test expands to
> one of -r, -w, -x etc, the shell will interpet the expanded variable name
> as a command.

  The C-shell is a VERY complicated program, obviously; it would
be nearly impossible to document how it would behave on every conceivable
possibility. But in any case, it DOES say that parsing and substitutions (which
presumably includes variable substitutions) are performed before the
command is executed.

--Greg



More information about the Comp.bugs.4bsd.ucb-fixes mailing list