Author Topic: [solved] why does "diff" always return "1"?!?  (Read 3681 times)

0 Members and 1 Guest are viewing this topic.

Offline DiTBhoTopic starter

  • Super Contributor
  • ***
  • Posts: 3915
  • Country: gb
Re: [solved] why does "diff" always return "1"?!?
« Reply #25 on: October 31, 2021, 09:19:35 am »
yup, but at least it's not buggy (well, ok, because - it, bash, and their friends - have been already updated) ;D
The opposite of courage is not cowardice, it is conformity. Even a dead fish can go with the flow
 

Offline bson

  • Supporter
  • ****
  • Posts: 2270
  • Country: us
Re: [solved] why does "diff" always return "1"?!?
« Reply #26 on: November 01, 2021, 03:52:54 am »
Thanks. Diff is used in a complex Bash script that needs to check if two files are equal or not, and in case not it needs to report differences. My script allocates the output of Diff in a variable to have it ready.
cmp is faster and if it were me I'd use a pattern like:

Code: [Select]
if ! cmp $FILE1 $FILE2 ; then
  echo '***' $FILE1 differs from $FILE2 '***'
  diff $FILE1 $FILE2
  exit 1
fi
This way, in the normal case where they don't differ you can quickly and silently move on and do nothing.  Then use diff to produce the actual message to print if they do differ.
 
The following users thanked this post: DiTBho


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf