-1

I have a two versions of a program, say : normalProgram and bruteProgram.

I have an input generator for both of these : programGenerator

Now I want to do this:

  • Put the output of ./programGenerator into input.txt : ./programGenerator > input.txt
  • Redirect input.txt as the input of normalProgram : cat input.txt | ./normalProgram
    • Put the output of ./normalProgram into op1.txt : (cat input.txt | ./normalProgram) > op1.txt
  • Similar thing for ./bruteProgram :
    • (cat input.txt | ./bruteProgram) > op2.txt
  • Now I want to compare op1.txt and op2.txt : diff op1.txt op2.txt

The whole command will look like this:

./programGenerator > input.txt &&
(cat input.txt | ./normalProgram) > op1.txt &&
(cat input.txt | ./bruteProgram) > op2.txt &&
diff op1.txt op2.txt

So this is a one time command.

I want to run this until diff op1.txt op2.txt gives a non-empty response.

I tried putting diff op1.txt op2.txt as the condition for until (or while, just to check whether the conditional is correct)

But this didn't work, and I got an error that, that is not a correct conditional.

Example:

while [diff normalOp.txt bruteOp.txt]
do
echo "hello"
done

This is giving me the error:

zsh: bad pattern: [diff
1

1 Answer 1

0

I just had to remove the square brackets from the condition:

while diff normalOp.txt bruteOp.txt  
do
echo "hello"
done

And this started working.


The exact bash command in this case would be:

while diff op1.txt op2.txt
while> do
while> ./programGenerator > input.txt   
while> (cat input.txt | ./normalProgram) > op1.txt
while> (cat input.txt | ./bruteProgram) > op2.txt
while> done
Sign up to request clarification or add additional context in comments.

1 Comment

The syntax error was one problem, but your current logic is "while diff produces some output, do a thing." What you have stated in the question would be "while diff produces no output, do a thing." This is for Bash, but should be similar in Zsh, though you could also make it simpler using until instead of while.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.