Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/17/84; site hao.UUCP Path: utzoo!watmath!clyde!cbosgd!hplabs!hao!woods From: woods@hao.UUCP (Greg Woods) Newsgroups: net.unix-wizards,net.bugs.4bsd Subject: Re: C-Shell weirdness (count of words in a variable) Message-ID: <2024@hao.UUCP> Date: Wed, 26-Mar-86 17:28:09 EST Article-I.D.: hao.2024 Posted: Wed Mar 26 17:28:09 1986 Date-Received: Fri, 28-Mar-86 07:23:23 EST References: <676@nbires.UUCP> <2021@hao.UUCP> <678@nbires.UUCP> Distribution: net Organization: High Altitude Obs./NCAR, Boulder CO Lines: 31 Xref: watmath net.unix-wizards:17358 net.bugs.4bsd:2013 > > 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