Hi,
I'm trying to process newline-separated output of a program by printing
only the first line that passes a test. forbacktickx program seems the
right tool, but I can't get it to work with -x 0. The actual test is a
separate program, here's a boiled-down example using eltest.
This correctly prints 2 "l2" lines:
forbacktickx -E line { printf "l1\nl2\nl3\nl2\n" }
if { eltest "${line}" = "l2" }
printf "${line}\n"
To exit after first match, I expected this to work, but it doesn't
output anything, just exits with 0:
# -x breakcodes : <...> listed exit codes are codes that will make
# forbacktickx break the loop and exit, and the unlisted exit codes will
# make it keep looping.
forbacktickx -x 0 -E line { printf "l1\nl2\nl3\nl2\n" }
if { eltest "${line}" = "l2" }
# on "l1" eltest exits with 1, if program exits with 1 and forbacktickx
# should continue to loop to "l2", right?
printf "${line}\n"
What's going on here, am I doing something wrong?
Received on Sat Jun 14 2025 - 19:08:24 CEST