Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/17/84; site nbires.UUCP Path: utzoo!watmath!clyde!cbosgd!hplabs!hao!nbires!nose From: nose@nbires.UUCP (Steve Dunn) Newsgroups: net.unix-wizards,net.bugs.4bsd Subject: Re: C-Shell weirdness (count of words in a variable) Message-ID: <678@nbires.UUCP> Date: Tue, 25-Mar-86 19:11:40 EST Article-I.D.: nbires.678 Posted: Tue Mar 25 19:11:40 1986 Date-Received: Fri, 28-Mar-86 07:22:32 EST References: <676@nbires.UUCP> <2021@hao.UUCP> Distribution: net Organization: NBI,Inc, Boulder CO Lines: 46 Xref: watmath net.unix-wizards:17357 net.bugs.4bsd:2012 Greg Woods writes in response to my article on c-shell weirdness: > > > 2: Count of number of words in a variable (Or when is nothing something) > > > > This: > > > > set hosed = '' > > echo $#hosed > > > > yields the result '1' > > But of course! The variable has one value: a null string. And, if you do > > set hosed=( '' junk) > > then what do you suppose $#hosed is? If you got 2, drink a potion of raise > level and read on! :-) If you do > > set hosed > echo $#hosed > > THEN you will get 0. The difference? A null string is different from no value > at all. This too has it's uses, such as when each word of a variable stands > for an attribute of the object represented by the variable, and a null string > means that attribute does not exist (i.e. a kludgy implentation of a > structure in a shell script. And yes, I'm masochistic; I actually have > real scripts that use this too :-) > Sorry, I tried the example that is supposed to yield zero and I got one instead. Furthermore, according to the manual page for csh under the set command "The second form [set name] sets name to the null string" The answer is that you can't have a variable with 0 words at all. This fact I find counter-intuitive and undocumented ---- The answers Greg gave to my questions on if tests and the not operator were correct and very helpful although 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. -Steve "Wrong Way" Dunn