loopwhilex

From: Olivier Brunel <jjk_at_jjacky.com>
Date: Wed, 18 Feb 2015 00:22:43 +0100

Hi,

Couple of things regarding loopwhilex:

- First off, I found the doc to be a bit confusing, because you
alternate between talking about when loopwhilex keeps running prog, and
when it stops/exits.

In fact, it's confusing enough that you yourself got it wrong :p
"
-n : negate the test: run prog... as long as it exits non-zero (or exits
a code that is *not* listed in breakcodes).
"

See that "not" that's in italic on the HTML page, well I believe it
should not actually be there, as -n actually means to run prog... as
long as it exits a code that *is* listed in breakcodes.

Again, might feel odd/confusing because the line above also mentions
something when it *is* listed in breakcodes, but it speaks about exiting
the loop instead of ending it there.

I feel picking one and only talking about that one, to make things
clearer/easier to follow, could be a good idea.

I'd suggest going with the "exits when"; say loopwhilex runs prog until
it exits non-zero, or exits one of the breakcodes. Then -n means to end
the loop if it exits zero, or not listed in breakcodes.

Even makes it easier to read: "-x 2" means stop on 2; "-n -x 0" means
stop on non-zero. It might feel a bit odd because "loopwhilex -x 2"
doesn't mean while it returns 2, but while it doesn't, but that's how it
works I guess (loopuntilx might have been a "better" name?).


- The phrasing on the doc led me to think that if prog is killed by a
signal, loopwhilex exits (that signal number). But looking at the code I
see that that's not the case, instead it will treat it as if prog had
returned 126. Why that magic number? Also, shouldn't it always exit when
prog was killed by a signal?


- And then, I was gonna ask for something, but as I kept thinking about
things I went another way, and in the end won't need/use loopwhilex
after all. But let me just mention the idea anyhow, just in case:

I was gonna say I'd like to get the exit code from prog that caused the
loop to end. So, I was thinking an option to make loopwhilex return the
exit code from prog, and maybe be killed by the same signal if prog was
signaled.

But then I thought as an alternative/better choice, how about a new
loopuntilx that works the same as loopwhilex, but that takes another
block as input:
  loopuntilx [ -n ] [ -x breakcodes ] { progloop... } prog...

It would run progloop until it exits non-zero (or one of the breakcodes)
(unless -n ofc) and then exec into prog, having set the ? environment
variable to the (last) exit code of progloop, or 256 if signaled.

But again, I won't need this after all, so I'm fine if you don't wanna
add this.


(As a side note though, if foreground would set that ? environment
variable to 256 instead of 111 when signaled it might be better, since
111 is a valid exit code after all.)

Cheers,
-j
Received on Tue Feb 17 2015 - 23:22:43 UTC

This archive was generated by hypermail 2.3.0 : Sun May 09 2021 - 19:38:49 UTC