This is my code:
#!/bin/bash -e
dirs=( * )
for f in "${dirs[@]}"
do
  while IFS= read -r line; do
     case "$line" in
       *disabled\>true* )
          sed -i '1i "$f"' list.txt;;
     esac
  done < "$f/config.xml"
done
Instead of sed, I tried echo and printf too but the the file list.txt is always empty. Why am I not able to append to file?
echo "$f" >> list.txt;;
printf '%s\n' "$f" >> list.txt;;
sample config.xml file under test folder:
<?xml version='1.0' encoding='UTF-8'?>
<project>
<disabled>true</disabled>
</project>
Goal: Print "test" into list.txt, if test/config.xml has <disabled>true in it.
bash -x yourscriptshow that the append lines (of which theprintfsolution is most robust) are actually invoked?printf 'line=%q\n' "$line"immediately within thewhile readbefore thecase, and find the individual line where it should be triggering but isn't, then you can include only the assignment of thelinevariable and then thecasestatement in your question, and leave out theforloop and not need any input files as a necessary part of reproducing the issue."$f"inside single quotes?