Editing Comparing files
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 1: | Line 1: | ||
== Comparison script == | == Comparison script == | ||
− | The script below takes two arguments on the command-line and compares them via <code>[https://en.wikipedia.org/wiki/Diff diff]</code> command. It also echoes generic human-readable answer saying whether two file system objects are equal. As <code>diff</code> | + | The script below takes two arguments on the command-line and compares them via <code>[https://en.wikipedia.org/wiki/Diff diff]</code> command. It also echoes generic human-readable answer saying whether two file system objects are equal. As <code>diff</code> compares directories as well as files, paths to directories are valid arguments as well. |
<source lang="bash"> | <source lang="bash"> | ||
Line 12: | Line 12: | ||
if [ -f "$1" -a -f "$2" ]; then | if [ -f "$1" -a -f "$2" ]; then | ||
− | + | : # OK, do nothing here | |
elif [ -d "$1" -a -d "$2" ]; then | elif [ -d "$1" -a -d "$2" ]; then | ||
− | + | : # OK, do nothing here | |
else | else | ||
if [ -f "$1" ]; then | if [ -f "$1" ]; then | ||
Line 30: | Line 30: | ||
fi | fi | ||
− | if diff | + | if diff "$1" "$2" > /dev/null 2>&1; then |
echo 'Equal' | echo 'Equal' | ||
else | else |