c - How to output 'passed' if a diff command results in no difference in bash? -


i writing shell script loops on ./tests directory , uses unix diff command compare .in , .out files against each other c program. here shell script:

#! /usr/bin/env bash  count=0  # loop through test files t in tests/*.in; echo '================================================================' echo '                         test' $count echo '================================================================' echo 'testing' $t '...'  # output results (test).res (./snapshot < $t) > "${t%.*}.res"  # test diff against (test).out files diff "${t%.*}.res" "${t%.*}.out"  echo '================================================================' echo '                         memcheck echo '================================================================'  # output results (test).res (valgrind ./snapshot < $t) > "${t%.*}.res"  count=$((count+1))  done 

my question how can add if statement script output 'passed' if diff command results in no difference? e.g.

pseudo code:

if ((diff res_file out_file) == '') {     echo 'passed' } else {     printf "failed\n\n"     diff res_file out_file } 

get , check exit code diff command. diff has exit code of 0 if no differences found.

diff ... ret=$?  if [[ $ret -eq 0 ]];     echo "passed." else     echo "failed." fi 

Comments

Popular posts from this blog

Django REST Framework perform_create: You cannot call `.save()` after accessing `serializer.data` -

Why does Go error when trying to marshal this JSON? -