csh exit(status)
Derek R. Foster
dfoster at jarthur.Claremont.EDU
Tue Mar 5 10:44:38 AEST 1991
Can anyone explain the following output? I looked at the csh man page under
"exit" and it said that exit(stat) would terminate a shell and return
exit status 'stat', where stat was an expression. However, I tried it, and
received the following results ( the '%' is my prompt):
% if { exit( 1 == 1 ) } echo "y"
% if { exit( 1 == 0 ) } echo "y"
y
% if { exit( 1 != 1 ) } echo "y"
y
% if { exit( 0 == 0 ) } echo "y"
As you can see, it appears that the opposite truth value is being returned.
When the expression ( 1 == 1, etc. ) is true, the value given to the 'if'
statement is false, and vice versa. This seems to be quite consistent.
(It makes no difference if I run the 'exit' command in a subshell by enclosing
the { } in ( ), just in case you were wondering.)
Why is this happening? Is this a bug or a feature? Can anyone else reproduce
these results?
The reason I am trying to do this is so that I can write, in effect,
user-defined functions along the lines of:
alias isxxxfile 'exit ( "\!*" =~ xxx* )'
if { isxxxfile $somefile } dosomething;
If there is an easier way to do this, I would appreciate information on it.
Mostly, however, I would like to understand why exit( ) seems to be logically
inverting its operands.
Any help would be greatly appreciated.
Thanks!
Derek Riippa Foster
More information about the Comp.unix.shell
mailing list