Multiline aliases in csh ?

Joe Wells jbw at bucsf.bu.edu
Thu Oct 25 18:58:50 AEST 1990


aps at tut.fi (Suntioinen Ari) writes:

	   Is there any way to define multi line alias in csh ?
	   What I mean is (for example) if-else or foreach loop 
	   as a part of alias.

Sure, here's an appropriately twisted example:

    alias which '(set argv=($path) target=\!*; whichi)'
    alias whichi 'if (! $#argv) set status=1 && whichii'
    alias whichii \
    'if (-x "$1/$target") set status=1 && shift && eval "whichi" \\
     || if ($#argv > 0) echo "$1/$target"'

Conditionals are done with:

    if (condition) set status=1 && else-statement || then-statement

Looping is done with recursion, which requires you to use "eval",
otherwise the csh will detect the recursion and refuse to do it.

Note, the last line should actually read:

     || echo "$1/$target"'

but yet another csh bug prevents it from working that way.

Enjoy,

-- 
Joe Wells <jbw at bu.edu>

PS.  I think this example clearly justifies why the author(s) of the csh
will be roasting in hell for a long long long time.



More information about the Comp.unix.shell mailing list