Help needed with conditional statement for alias in csh
Chris Torek
chris at mimsy.umd.edu
Sat Sep 15 01:24:25 AEST 1990
In article <6932.26ed237f at uwovax.uwo.ca> miller at uwovax.uwo.ca
(Greg Miller) writes:
>Followup-To: j g miller <miller at ria.ccs.uwo.ca>
(No wonder there have been no followups. None of `j', `g', `miller', or
`<miller at ria.ccs.uwo.ca>' are valid newsgroup names....)
>if ( { test -s /usr/spool/mail/miller } ) then; echo "" ; echo "New mail" ;\
> echo "" ; endif
>If the file is present, the condition is met and the statements are
>executed.
>
>If the file is zero length, the condition is not true, then
>the sequence of commands are not executed but the if statement
>is not terminated.
Correct.
>Any ideas on why this bizarre behavior
This is the C shell we are talking about. Do not expect anything
resembling sanity.
>and how to get it to work properly?
Do not use an alias.
The C shell's `parser' looks for a *line* whose first word is `else' or
`endif' after the C shell executes a false `if (expr) then'. While
scanning for such a line it notes lines that have the form
if<whitespace>.*<whitespace>then
and increments a `false if' counter. You can thus stick all sorts of
syntactic trash between a false `if' and its corresponding `endif'; only
when the test in the `if' becomes true will the C shell actually notice
that the trash is indeed invalid. For instance:
if (0) then
if (look, unclosed { and !funny characters then
endif
echo this does not get echoed
endif
echo but this does
It *is* possible to jam a newline into an alias, but if you do you will
quickly run afoul of other C shell bugs. For instance:
% alias t 'if (0) then\
echo foo\
endif\
echo bar'
% t
? ? %
Nothing gets echoed.
--
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 405 2750)
Domain: chris at cs.umd.edu Path: uunet!mimsy!chris
More information about the Comp.unix.shell
mailing list