I can't find my answer anywhere. The counter in my code doesn't work. Why and what to do ?
count=0;
for file1 in folder1;
do
    cat $file1 | while read line
    do
        echo $line;
        ((count++));
    done
done
echo "Count : ${count}";
I can't find my answer anywhere. The counter in my code doesn't work. Why and what to do ?
count=0;
for file1 in folder1;
do
    cat $file1 | while read line
    do
        echo $line;
        ((count++));
    done
done
echo "Count : ${count}";
When using a pipeline, the commands are executed in a subshell. Changes in a subshell don't propagate to the parent shell, so the counter is never incremented.
You don't need a pipeline here. Use a redirection instead:
    count=0
    while read line
    do
        echo $line;
        ((count++));
    done < "$file1"