One line If-then-else block in csh possible?
Tom Christiansen
tchrist at convex.COM
Mon Feb 18 03:49:57 AEST 1991
>From the keyboard of tchrist at convex.COM (Tom Christiansen):
:From the keyboard of harichan at 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 at convex.com convex!tchrist
"All things are possible, but not all expedient." (in life, UNIX, and perl)
More information about the Comp.unix.shell
mailing list