What you have posted here make no sense. As written, this line
result=(( "$result" + "$pathname" ))
, seems to be trying to accumulate
something to
result
, but since you have
for pathname in CWFiles/**/*.txt
then
pathname
will hold a value something like
CWFiles/foo/bar.txt
. Clearly, that's not a number, so the attempt at addition is not going to work. It looks like you're trying to use integer math in a bash script, so you might want to use
let
or
declare
expressions instead. Incidentally,
let
expressions do octal math as expected:
[k5054@localhost tmp]$ let result=10
[k5054@localhost tmp]$ echo $result
10
[k5054@localhost tmp]$ let result+=10
[k5054@localhost tmp]$ echo $result
20
[k5054@localhost tmp]$ let result+=010
[k5054@localhost tmp]$ echo $result
28[k5054@localhost tmp]$
Maybe you want something more like:
shopt -s dotglob nullglob
shopt -s globstar
let result=0
for pathname in CWFiles/**/*.txt; do
[ ! -f "$pathname" ] && continue
while read -r line
do
let result+=$line
echo $result
done < "$pathname"
done