Skip to content

Instantly share code, notes, and snippets.

@joaquinco
Created March 28, 2022 15:13
Show Gist options
  • Save joaquinco/12167db2aa18375e52dfce2de1e36513 to your computer and use it in GitHub Desktop.
Save joaquinco/12167db2aa18375e52dfce2de1e36513 to your computer and use it in GitHub Desktop.
diff for directories
#!/bin/bash
: "
Compare files from the first to the same filename
in the second directory, if they both exist.
"
DIFF_VER=${DIFF_VER:-diff}
dir1=$1
dir2=$2
if [ -z "$dir1" -o -z "$dir2" ]; then
echo "Usage $0 <directory1> <directory2>"
exit 1
fi
for file in $(ls $dir1); do
full_path1=$dir1/$file
full_path2=$dir2/$file
if [ ! -f "$full_path1" -o ! -f "$full_path2" ]; then
continue
fi
diffout=$($DIFF_VER $DIFF_ARGS $full_path1 $full_path2)
if [ $? -ne 0 ]; then
echo "$DIFF_VER $full_path1 $full_path2"
echo "$diffout"
fi
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment