I've already answered your other question Syntax error in a bash script that calls find, so I won't repeat what I already wrote in my answer there.
Do not parse the output of ls. You don't need to run ls to enumerate files in a directory. Use find if you need to recurse into subdirectories.
To get the output of wc -l, use it in a command substitution: $(git log "$f" | wc -l)
Note that you need double quotes around the variable name. Always use double quotes around variable and command substitutions: "$foo", "$(foo)". Double quotes turn off the shell's further processing of the value of the variable or command output: without quotes, the result is split into words which are interpreted as file wildcard patterns. With single quotes, the $ sign is not treated specially, so git would see $f instead of the value.
find . -type f -exec sh -c '
for x in "$@"; do
c=$(git log "$f" | wc -l)
done
' _ {} +
The use of -exec … {} + instead of -exec … {} \; allows the intermediate shell to be invoked only once per large batch of files, which is a bit faster.
Since bash ≥4, you don't need to use find, you can use the ** syntax to recurse into subdirectories.
shopt -s globstar
for x in **/*; do
[ -f "$x" ] || continue # skip directories and other non-regular files
git log "$x" | wc -l
done
$dvariable. – manatwork Oct 10 '12 at 9:34ls. – manatwork Oct 10 '12 at 9:38