Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!gatech!uflorida!haven!mimsy!chris From: chris@mimsy.UUCP (Chris Torek) Newsgroups: comp.unix.questions Subject: sh if-then-else (was Re: How to tell if you're in a pipe...) Keywords: pipe tty(1) sh(1) isatty(4) Message-ID: <18353@mimsy.UUCP> Date: 1 Jul 89 20:31:46 GMT References: <1798@lgnp1.LS.COM> Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742 Lines: 25 In article <1798@lgnp1.LS.COM> rbarrell@lgnp1.LS.COM (Robert Barrell) writes: > if [ `tty -s;echo $?` = 0 ] This is rather the hard way around: a simple if tty -s will suffice. The result of if list; then true-branch; else false-branch; fi is `true' if the exit status (here, `$?') of the command-list `list' is zero, and false otherwise, so that the `if' runs the true-branch if `tty -s' exits 0 and the false-branch if `tty -s' exits nonzero (1). To get this effect in the C shell, one must write if { tty -s } then (`if ({ list }) then' is also accepted). Watch the spacing; the words `if' and `then' must not be run into their parentheses or braces. -- In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163) Domain: chris@mimsy.umd.edu Path: uunet!mimsy!chris