Tom
Tom

Reputation: 6971

Running test until failure and viewing full debug: Bash not displaying output of command properly

I am getting a non-deterministic crash in a library I am using which occurs a lot less frequently when the library's full debugging is turned on. I want to run it repeatedly until the program crashes, and then look at the detailed debug (let's assume that unit-test-command with args calls the code I am interested in)

This is the code I have in my script:

#!/bin/bash

while [[ $(unit-test-command with args) == 0 ]]
do
    echo ""
done

However, not only does it only go through the loop once irrespective of the return value of the command (which is non-zero when it crashes), but it also only displays the output of my program, and not the output of the library debugging.

What I am doing wrong?

Upvotes: 1

Views: 243

Answers (2)

michael501
michael501

Reputation: 1482

#!/bin/bash 

while [ true ];do 
   unit-test-command with args
   if [ $? != 0 ];then    
       echo "failed"
       break
   fi
   echo "didn't faile
   sleep 10
done

Upvotes: 0

user2743554
user2743554

Reputation: 543

$(command) expands to the console output, not to return code. For example, uname returns 0 and $(uname) returns "linux".

Try so:

while unit-test-command with args ; do : ; done

Upvotes: 4

Related Questions