How to verify whether a XML file is valid in sh (preferably) or bash?
I have a file that often get corrupted and needs to be replaced while I take my time to investigate the underlying issue.
Is there any easy way of performing this task with sh or bash?
Not directly with bash, but xmllint
is fairly widely available.
xmllint --format "${xmlfile}"
This will exit with non-zero status (hint: $?
in bash gets you the exit code of the last command) if the XML file is invalid.