0

I am new to bash scripting. I can do this:

while [ read line ] 
do
    # do something with $lin
done

I can also do this:

while [ checkBufferedLines ]
do
    # do something
done

But what I'm wanting to accomplish is something like this:

while [ read line ] || [ checkBufferedLines ]
do
    # do something with $line or the buffered lines
done

Concisely, I want the loop to run if a $line is assigned from stdin or if a function call returns true or 1, and I would like a $line to short-circuit the function call if present.

That's what I'm trying to accomplish; can this be done? Or will read line stop the loop so the checkBufferedLines function isn't also evaluated on the 'or' condition?

Oliver Williams
  • 5,966
  • 7
  • 36
  • 78
  • 1
    The `read` call is blocking. The right side of the conditional will only be evaluated after read completes the stream and returns false. – jordanm Apr 01 '20 at 15:42
  • `while [ read line ] ` will not work -- you use `[ ]` to evaluate a conditional expression (e.g. `[ 5 -lt 7 ]`), not to contain a command like `read`. See: [Bash conditional based on exit code of command](https://stackoverflow.com/questions/49849957/bash-conditional-based-on-exit-code-of-command/49850110). – Gordon Davisson Apr 01 '20 at 15:57

0 Answers0