C-Shell weirdness

Steve Dunn nose at nbires.UUCP
Wed Mar 26 03:40:01 AEST 1986


I've been foolish enough to try to write a shell script lately. I'm 
using the C-shell on 4.2 berkley UNIX. Since both UNIX and its 
documentation are for me just a bit cryptic (Ahem) I can't even be 
sure what's a bug and what's actually really intended to be that way, so
I'm posting this to both bugs and wizards. I am interested in anyone who
has solutions to or explanations for any of these problems.

1. if tests:

   the statement:

           if ($arg == '-b') echo 'UNIX is fun'

Will get the error "If: missing filename" if $arg happens to equal
-x or -e or any of the other constructs used to test file attributes.
The statement will NOT fail if $arg happens to equal other reserved
words such as "if" or "foreach". I did find a kludge to get
around this but it makes be want to rip out my intestines with a fork.
(Well actually its not quite *that* bad...) The statement can be replaced
by this one:

	 if (x$arg == 'x-b') echo 'UNIX is fun'

Is there a better way to do this and why does this happen in the first
place?

2: Count of number of words in a variable (Or when is nothing something)

This:

set hosed = ''
echo $#hosed

yields the result '1'

It seems to me that a variable with null contents has ZERO words not one

3: Logical not operator

According to the csh man page the logical not operator "!" is available.
Unfortunately the statements (in a shell script)

set lights_on = 1
if (!$lights_on) echo 'nobody home'

yield the message "0: event not found". Apparently the shell is trying
to do a history substitution instead of a negation. I have tried all 
manner of quoting to get around this - nothing works. Well then, given that
"!" is used both to signal history substitutions and as a logical not
operator, how can you tell which the shell will choose to do in a given
situation?

                -Steve "If I only had a brain..." Dunn



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