Using Ubuntu 20.04.4 LTS (Focal Fossa) and diff (GNU diffutils) 3.7
History at:
How to capture and reuse diff result?
While testing this script below ...
Two directories were made different by
changing one Letter in file name from
abc.txt to Abc.txt capital A
script works and says:
diff -rq src1/ dest/ Differences were found. ________________________________________ dirs differ
script is:
src1='/media/u3/usb_stick' ; dest='/home/u3/Music/x' ;
diff -rq "$src1/" "$dest/" ;
if [ $? -eq 0 ] ; # testing exit status ( 0 <--> match ) No differences echo $? = exit code = 0 ;
then
match21=true ;
else
match21=false ;
fi ;
echo ;
if $match21 ;
then
tput setaf 12 ; echo "diff -rq "src1/" "dest/" " |tr '\n' ' ' ;
tput sgr0 ; echo "Match. Same inputs. All ok. No difference. Success. " ;
else
echo "diff -rq "src1/" "dest/" Differences were found. ________________________________________ dirs differ" ;
fi ;
But then there is a problem ...
when the diff command is commented out #
the result is incorrect:
diff -rq src1/ dest/ Match. Same inputs. All ok. No difference. Success.
above result is incorrect.
commented out # script is
src1='/media/u3/usb_stick' ; dest='/home/u3/Music/x' ;
# diff -rq "$src1/" "$dest/" ;
if [ $? -eq 0 ] ; # testing exit status ( 0 <--> match ) No differences echo $? = exit code = 0 ;
then
match21=true ;
else
match21=false ;
fi ;
echo ;
if $match21 ;
then
tput setaf 12 ; echo "diff -rq "src1/" "dest/" " |tr '\n' ' ' ;
tput sgr0 ; echo "Match. Same inputs. All ok. No difference. Success. " ;
else
echo "diff -rq "src1/" "dest/" Differences were found. ________________________________________ dirs differ" ;
fi ;
How to fix side-effect surrounding diff script?
This means when not running diff, commented out #
# diff -rq "$src1/" "$dest/" ;
then have no message or
show a minus sign, a filler:
-
as a message.