I have the following script:
ls -l | while read permissions number user user2 size month day hour filename
do
if [[ "$filename" == *foo* ]]
then
scount=`expr $scount + $size`
fi
done
echo $scount
The script checks the filename and size of the files in my folder, then it checks for files which contain 'foo' word, then it takes it size and adds it.
I have the following problem, if I call the scount variable from inside the loop it displays the numbers, but when it is outside it shows nothing, as if the variable does not exist. Does it have something to do with shell sessions? How can I display the variable outside of the loop?