Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Path: utzoo!watmath!clyde!burl!ulysses!mhuxr!mhuxt!houxm!whuxl!whuxlm!akgua!gatech!seismo!mcvax!vu44!botter!ark!maartenj From: maartenj@ark.UUCP Newsgroups: net.unix-wizards,net.bugs.4bsd Subject: Re: C-Shell weirdness (count of words in a variable) Message-ID: <713@ark.UUCP> Date: Sat, 29-Mar-86 19:22:59 EST Article-I.D.: ark.713 Posted: Sat Mar 29 19:22:59 1986 Date-Received: Tue, 1-Apr-86 07:21:10 EST References: <676@nbires.UUCP> <2021@hao.UUCP> <678@nbires.UUCP> <2024@hao.UUCP> Reply-To: maartenj@vu44.UUCP (Huisjes Maarten Jan) Distribution: net Organization: VU Informatica, Amsterdam Lines: 45 Xref: watmath net.unix-wizards:17412 net.bugs.4bsd:2027 In article <2024@hao.UUCP> woods@hao.UUCP writes: >> > 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. Try : set hosed = () echo $#hosed This will give you 0. The point is the definitions of a `word'. A word is defined as being separated by a tab, space or newline accept when the string, containing these characters, is enclosed in `'' or `"' (with one exception when you do something like: "`cat /etc/passwd`" this will force new words at newlines). The actual syntax is of `set' is : set arg = ( wordlist ) when you only set the arg to one word you can leave out the `(' and `)': set arg = word Finally you have the abbreviation : set arg This is exactly the same as set arg = '' e.i. it will set arg to a null string. So $#arg will give the number of words in $arg. -- Maarten Jan Huisjes. (maartenj@vu44.UUCP) {seismo|decvax|philabs}!mcvax!vu44!maartenj