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!brl-adm!brl-smoke!smoke!reschly@BRL.ARPA From: reschly@BRL.ARPA Newsgroups: net.unix-wizards Subject: Re: C-Shell weirdness (count of words in a variable) Message-ID: <2207@brl-smoke.ARPA> Date: Sat, 29-Mar-86 20:28:52 EST Article-I.D.: brl-smok.2207 Posted: Sat Mar 29 20:28:52 1986 Date-Received: Tue, 1-Apr-86 07:20:03 EST Sender: news@brl-smoke.ARPA Lines: 42 > 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. Another case where the $#variable construct can be zero is in the case of shell input. Using the following code (from my .login): switch ($term) . . . case tty5620: echo -n "TERM type? (is: $term default: dmd): " set termin=($<) if( $#termin ) then set term=$termin else set term=dmd endif breaksw default: echo -n "TERM type? (is: $term default: $term): " set termin=($<) if( $#termin ) set term=$termin endsw In the above code, if only a carriage return is typed at the prompt, the default (if different from the current value) is assigned to the term variable. If anything else is typed, it is assigned to the term variable. For those who have not seen this construct before, be warned that the format of the sets following the echos is critical. I do not remember exactly what the problem was, but I think it was that the righthand side of the equals sign must be exactly as shown above. Later, Bob