diffreturn-code

Why does the simplest example of patch creation not work?


How can

echo "a" > a
echo "b" > a.new
diff -u a a.new > a.patch
patch -u -p1 < a.patch

fail at the diff command with return code 1 and no output?


Solution

  • diff returns 1 if differences are found (see What are the error exit values for diff? for more info on return codes) even if stdout is redirected into a file which isn't overly helpful in my point of view.