简体   繁体   中英

Comparing inputs and outputs - bash

Say i have an input file and an output file (test.in and test.out) and a program "./myprogram" with standard input redirected to come from test.in and use the results that are captured from standard output to be compared with test.out

how exactly can i compare

Im Thinking,

 if [ $(myprogram < test.in) == $(cat test.out) ]

Any suggestions?

Use cmp and specify - as one of the files to compare, which tells it to use stdin.

if myprogram < test.in | cmp -s - test.out; then

If you want to compare the output of two commands without creating temp files, use the <(cmd) feature. (Search for "Process Substitution" in man bash .)

if cmp -s <(myprogram < test1.in) <(myprogram < test2.in); then

Or diff if you want to know what the differences are.

I'd use diff. Something like this:

if cat test.in | myprogram | diff - test.out

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM