Path: utzoo!mnetor!tmsoft!torsqnt!news-server.csri.toronto.edu!cs.utexas.edu!convex!news From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.unix.shell Subject: Re: One line If-then-else block in csh possible? Keywords: csh programming Message-ID: <1991Feb17.164957.612@convex.com> Date: 17 Feb 91 16:49:57 GMT References: <1991Feb13.180658.16244@msuinfo.cl.msu.edu> <1991Feb16.142134.19813@convex.com> Sender: news@convex.com (news access account) Reply-To: tchrist@convex.COM (Tom Christiansen) Distribution: comp Organization: CONVEX Software Development, Richardson, TX Lines: 28 Nntp-Posting-Host: pixel.convex.com From the keyboard of tchrist@convex.COM (Tom Christiansen): :From the keyboard of harichan@eecae.uucp (Ronald Harichandran): ::Is it possible to have an if-then-else-endif block on a single line? : :You can often work something out using /bin/test and the short-circuit :booleans: : : [ some test ] && success || failure : As was so kindly pointed out to me in private, that doesn't work. If the "success" command fails, then the "failure" command will be executed, which isn't what was asked for. So to guarantee that success always succeeds, add a subshell (gag) and append a gratuitous true: [ some test ] && (success || true) || failure Maybe it's time to switch shells so you can code your if's the way they were Meant to be. :-( if [ some test ] ; then success_cmd; else failure_cmd; fi --tom -- Tom Christiansen tchrist@convex.com convex!tchrist "All things are possible, but not all expedient." (in life, UNIX, and perl)