test the exit status inside a shell
David Elliott
dce at mips.COM
Sun Oct 2 07:28:12 AEST 1988
In article <826 at philmds.UUCP> leo at philmds.UUCP (Leo de Wit) writes:
>while command1; do commands; done # while command1 succeeds do the commands
>until command1; do commands; done # until command1 succeeds do the commands
>if command1; do commands; done # if command1 succeeds do the commands
^^ ^^^^
"if" in sh uses "then" and "fi", not "do" and "done", but that's not what
I followed up for.
An interesting note about while and until is that the actual syntax is
while list; do list; done
where a "list" is a list of commands (the semicolons can be newlines).
This means that the loop
a=no
while
echo "Enter a new value for a: \c"
[ "$a" != "no" ]
do
read a
echo "Entered $a"
done
is a legal loop. I've only seen this used once, but it could be useful
as fast machines make it more reasonable to use sh to write interactive
commands.
--
David Elliott dce at mips.com or {ames,prls,pyramid,decwrl}!mips!dce
More information about the Comp.unix.questions
mailing list