#!/bin/env bash # Create a temporary file temp_file=$(mktemp) # Run xmllint and output to the temporary file if xmllint --format "$1" >"$temp_file"; then # If successful, replace the original file with the formatted file mv "$temp_file" "$1" else # If unsuccessful, remove the temporary file rm "$temp_file" echo "Formatting failed." exit 1 fi