I use this command for test my html pages for errors:
find . -iname '*html' -type f -print -exec /usr/local/bin/tidy -q -e {} \;
And I want to get exit code > 0 if any errors was founded by tidy.
find always return me 0.
Is there any way to sums exit code from tidy, and return it from find or any other wrapper script?
You could try something like this:
This would only print out filenames for which
tidy
exited with an error code. You could use-fprint
to collect the filenames in a file:These constructs take advantage of the fact that
-exec
is a boolean expression that returns true or false depending on the success of the command; the-o
flag is a booleanOR
, so this reads:find all entries that match
*html
AND that are files AND ( for which tidy returns true OR print the filename)Try this:
Explanation: You'll want to loop through the results of the
find
command, runtidy
, then increment a counter if an error is found (I assumetidy
will generate a non-zero return code on error).Once you've looped through the files, if there are any errors, you can
exit 1
, and it's always good practice to explicitlyexit 0
if things completed successfully.