I am attempting to iterate through files in target and all sub directories, calculate their hash, and save all this in a file in each sub directory. I paste here only part of the code. The code works, despite spaces in directory names. All files get listed and hashed (the hash command is ## to test quicker)
Only one thing gets me frustrated. I am trying to get counters to increment but that does not work, whatever I do (changing initial to 1 instead of 0 for example) ccctr does not get modified by increments.
ccctr=$ccctr+1
let "ccctr++"
let "ccctr+=1"
let "ccctr=ccctr+1"
do not work either. I searched but could not find solutions.
Please help anyone?
`#!/bin/bash
cd /target
#find all directories including subs
allD=$(find . -type d -print0 | xargs -0 -n 1 echo)
#Create Counter
ccctr=1
echo counter = $ccctr
#go through all directories, caring for names with spaces
echo "$allD" | while read -r a
do
#find all files in directory, not recursive, caring for names with spaces, excluding some
allF=$(find "$a" ! -name '.DS_Store' ! -name '.localized' -maxdepth 1 -type f -print0| xargs -0 -n 1 echo)
#go through all files
echo "$allF" | while read -r b
do
let "ccctr=ccctr+1"
##shasha=$(shasum -a 512 "$b")
shasha="$b"
echo b: $shasha
done
echo --------$ccctr total Files Found
done`