Check whether a root file was closed properly (with bash)

See Corrupted ROOT files without reason ?!

#!/bin/bash
for filename_to_check in *.root
  do
    root.exe -b -l -q -e "auto f = TFile::Open(\"$filename_to_check\"); if (f == nullptr || f->IsZombie()) { cout << \"There is a problem with the file: $filename_to_check\n\"; exit(1); }"
    if [ $? -ne 0 ]; then
        echo $filename_to_check has error
        exit 1
   fi
 done ;