sh if-then-else (was Re: How to tell if you're in a pipe...)
Chris Torek
chris at mimsy.UUCP
Sun Jul 2 06:31:46 AEST 1989
In article <1798 at lgnp1.LS.COM> rbarrell at 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 at mimsy.umd.edu Path: uunet!mimsy!chris
More information about the Comp.unix.questions
mailing list