Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!uunet!olivea!bu.edu!nntp-read!jbw From: jbw@bigbird.bu.edu (Joe Wells) Newsgroups: comp.unix.shell Subject: Re: One line If-then-else block in csh possible? Message-ID: Date: 14 Feb 91 16:46:38 GMT References: <1991Feb13.180658.16244@msuinfo.cl.msu.edu> Sender: news@bu.edu.bu.edu Distribution: comp Organization: Boston University Computer Science Department Lines: 24 In-reply-to: harichan@eecae.uucp's message of 13 Feb 91 18:06:58 GMT In article <1991Feb13.180658.16244@msuinfo.cl.msu.edu> harichan@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