4.6.2 early report
Duncan
1i5t5.duncan at cox.net
Mon Apr 11 23:12:49 BST 2011
gene heskett posted on Mon, 11 Apr 2011 07:11:52 -0400 as excerpted:
> This wait for kmail code snippet falls right thru even when kmail
> isn't running:
>
> ==========
> DetectKmail="pgrep kmail"
> until :
> do
> sleep 3
> $DetectKmail
> done
> ==========
>
> As I read the bash docs in the scripting guide, the until loop will
> run till a non-zero output is obtained from the last command in the
> loop.
>
> while list; do list; done
> until list; do list; done
> The while command continuously executes the do list as long
> as the last command in list returns an exit status of zero.
> The until command is identical to the while command, except
> that the test is negated; the do list is executed as long as the
> last command in list returns a non-zero exit status. The exit
> status of the while and until commands is the exit status of the
> last do list command executed, or zero if none was executed.
> If kmail isn't running $DetectKmail's return s/b a null. What is
> my mistake? Ahh, s/b a "while" :, ENOTENOUGHCAFFIENE ;-)
>
> Off to test that.
I see you've posted the "while" results, but am posting this here
so as to keep the reply there shorter. The below applies to
"while" as well, except with the reverse logic.
You're misreading the docs! =:^(
Of course in this case the doc has a regrettable ambiguity, in that
there's two "lists" that "last command in list" could refer to.
The "list" referred to is the first one, the test list, not the
second, loop-body list.
Here's what bash itself has to say about until (help is a bash
builtin similar to the --help option many commands offer, so
entering "help until" yields bash's help on the "until" builtin):
until: until COMMANDS; do COMMANDS; done
Execute commands as long as a test does not succeed.
Expand and execute COMMANDS as long as the final command in the
`until' COMMANDS has an exit status which is not zero.
Exit Status:
Returns the status of the last command executed.
Meanwhile, "help :"
:: :
Null command.
No effect; the command does nothing.
Exit Status:
Always succeeds.
So what that until block you have there does is:
"Execute a loop until an always successful null-command succeeds."
IOW, the loop is never run...
You effectively commented out your loop! =:^)
If it was a while instead of until, you'd have an endless loop,
which you'd then need to break (help break...) out of somewhere
in the loop.
ENOTENOUGHCAFFIENE indeed! =;^P
--
Duncan - List replies preferred. No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master." Richard Stallman
___________________________________________________
This message is from the kde mailing list.
Account management: https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.
More information about the kde
mailing list