hello everyone. i am writing a function, which renames desired files. first pattern matching part of the file from the end (mostly because of extensions). i am almost done, but one thing annoys me:
i am getting the list of files through
find and then reading the list with
while read, so i can avoid troubles with whitespaces in the name of files. the thing is, i need to count, how many of the files was actually renamed, but i can't get it once the
while ends...
the important part of the code goes like this:
(imagine 1 file matching the pattern)
Code:
rename()
{
count=0;
...
find $pattern -prune -type f | while read i; do
...
echo $count ##### =0
while [ $changed -eq 0 ] && [ $offset -ge 0 ]; do
if test "${i:$offset:${#match}}" == $match; then
...
((count++))
echo $count ##### =1
fi
done
echo $count ##### =1
done
echo $count ##### =0
}
so my question is: is there any way how to get that information out of the subshell? or is there some other way how to read a file (variable) line by line, which doesn't involve using a subshell?