Advertisement
Guest User

xml_formatting_script_with_path

a guest
May 28th, 2024
70
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 1.02 KB | Source Code | 0 0
  1. #!/bin/bash
  2.  
  3. export XMLLINT_INDENT="    "
  4.  
  5. process_xml_files() {
  6.     local dir="$1"
  7.  
  8.     echo "Processing directory: $dir"
  9.  
  10.     if [ ! -d "$dir" ]; then
  11.         echo "Directory $dir does not exist."
  12.         return
  13.     fi
  14.  
  15.     # Loop through each file in the directory
  16.     for file in "$dir"/*; do
  17.         if [ -d "$file" ]; then
  18.             # If the file is a directory, then recurse into it
  19.             process_xml_files "$file"
  20.         elif [[ "$file" == *.xml ]]; then
  21.             # If the file is an XML file, run the diff command
  22.             echo "Processing file: $file"
  23.             diff -B --tabsize=4 "$file" <(xmllint --format "$file")
  24.         else
  25.             echo "Skipping non-XML file: $file"
  26.         fi
  27.     done
  28. }
  29.  
  30. # Check if at least one argument is passed
  31. if [ $# -eq 0 ]; then
  32.     echo "Please provide path(s) to the directory"
  33.     echo "Usage: $0 path1 [path2 ... pathN]"
  34.     exit 1
  35. fi
  36.  
  37. # Loop through all the arguments (paths)
  38. for path in "$@"; do
  39.     process_xml_files "$path"
  40. done
  41.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement