10.7 How to Put if-then-else in a C Shell Alias
The C shell's
brain damage (
47.2
)
keeps you from using an
if
(
47.3
)
with an
else
in an alias.
You have to use a
sourceable script (
10.5
)
.
Or that's what I thought until I saw an article by Lloyd Zusman on
comp.unix.questions
in December 1987.
He'd saved an earlier posting on that group (but without its author's name)
that showed how.
The trick: use enough backslashes (
As an example, here's an alias named
C
for
compiling (
52.8
)
C programs.
It needs the
executable
filename (like
Your alias doesn't need to be as complicated.
But this one shows some tricks, like putting an
if
inside the
if
, that you might want to use.
The expressions like
# COMPILE AND chmod C PROGRAMS; DON'T USE .c ON END OF FILENAME. alias C 'eval "if (\!* =~ *.c) then \\ echo "C quitting: no .c on end of \!* please." \\ else \\ if (-e \!*) mv \!* \!*.old \\ echo \!*.c SENT TO cc \\ cc -s \!*.c -o \!* \\ if (-e \!*) chmod 311 \!* \\ endif"' - |
|