I have a script which greps for particular patterns and update them.
I also need the count of number of files that are updated.
I need to write that count to $GITHUB_ENV
During increment, the variable is assigning correct value. But when writing it to $GITHUB_ENV, it is writing initial value of the variable.
counter=0
grep -ril "search_pattern" ${directory_path%/} | while IFS= read -r file; do
counter=$((counter + 1))
echo "Script file: $file"
done
echo "COUNTER=$counter" >> $GITHUB_ENV
While executing the last line - echo, it's always giving 0 for $counter even though I see the $counter getting updated inside the loop.
I used set -x to see it the variable is getting updated inside the loop. and it is updating.