The C shell's
keeps you from using an
with an else in an alias.
You have to use a
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 (
\) and the
As an example, here's an alias named C for
C prog), not the
source filename (like
If you type a filename ending in .c, it complains and quits.
Renames any old prog file to prog.old,
Prints the message
SENT TO cc,
And - if there's a prog file (if the compile succeeded)-runs chmod 311 prog to protect the file from accidental reading with a command like cat * or more *.
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
-e are explained in article
Watch your quoting - remember that the shell strips off one level of
and another during the first pass of
Follow this example and you'll probably be fine:
# 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"'