Iceforest
Iceforest

Reputation: 341

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

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

Upvotes: 1

Views: 52

Answers (1)

oguz ismail
oguz ismail

Reputation: 50805

Just pipe the script's output to cmp.

./script | cmp -s - file

Upvotes: 3

Related Questions