One line If-then-else block in csh possible?
Joe Wells
jbw at bigbird.bu.edu
Fri Feb 15 03:46:38 AEST 1991
In article <1991Feb13.180658.16244 at msuinfo.cl.msu.edu> harichan at eecae.uucp (Ronald Harichandran) writes:
Is it possible to have an if-then-else-endif block on a single line [in csh]?
Yes, but it's a rather twisted/convoluted kludge:
if ( [boolean condition] ) set status=1 && [else clause] || [then clause]
I always forget that I have to put the else clause first or negate the
condition. Here's a simple example of this technique used in an alias:
alias h \
" if ('\!*' != '') set status=1 && hi \\
|| if ('\!*' !~ [1-9]*) set status=1 && hi -\!* \\
|| history | grep -i '\!*' | tail"
alias hi 'history | grep ............ | tail'
If you're just starting with the csh and you haven't already invested a
lot of time in customizing it, you're better of switching to bash or ksh.
--
Enjoy,
Joe Wells <jbw at bu.edu>
More information about the Comp.unix.shell
mailing list