I have this bash 4.3 script:
#!/bin/bash
for x in *.xml; do
badid=$(xml sel -t -v "//bad/@id" "$x")
vg=${badid%\.*}
count=$(xml sel -t -v 'count(//bad/objdesc/desc/@id)' "$x")
for ((i=1; i<=count; i++)); do
id=$(xml sel -t -v "//bad/objdesc/desc[$i]/@id" "$x")
count2=$(xml sel -t -v 'count(//bad/objdesc/desc[$i]/objtitle/objid/objcode/@code)' "$x")
for ((j=1; j<=count2; j++)); do
bentleynum=$(xml sel -t -v "//bad/objdesc/desc[$i]/objtitle/objid/objcode[$j]/@code" "$x")
if [[ $bentleynum == B* ]]; then break; else continue; fi
done
cat<<EOF
$vg.$bentleynum $id
EOF
done
done
I get this error:
runtime error: element call-template
Variable 'i' has not been declared.
xmlXPathCompiledEval: 1 objects left on the stack.
Does this have to do with the fact that I'm trying to use $i in the sub-loop? How do I use it globally (in the sub-loop)?