Home > Blockchain >  how to compare the output from a bash script with a file?
how to compare the output from a bash script with a file?

Time:11-18

there is a file, let's call it a reference file, you need to execute the script and compare the reference file with it, a file of 132 kb

result=$(./test.sh)| cmp -s $result test && echo 1||echo 0

I get the wrong output, the test file is identical to the script output, but I get 0

CodePudding user response:

Just pipe the script's output to cmp.

./script | cmp -s - file
  •  Tags:  
  • bash
  • Related