The only external (to bash) tool you really need is file(1)... Try this
prototype script (also, see [1]):
You can remove the need for file(1) too.
shopt -s globstar
# shopt -s nullglob # not needed, [[ -f $f ]] will return false
knownscripts_re='^ *#! *.*/?(php|python[[:digit:]]*|bash|sh)( |$)'
shebang_re='^ *#!'
for f in ./**/*; do
[[ -f $f ]] || continue
read -r header < "$f"
if [[ ${header:0:4} = $'\x7fELF' ]]; then
echo "$f is an elf binary and should be chmodded"
elif [[ $header =~ $knownscripts_re ]]; then
echo "$f is a python/php/shell script and should be chmodded"
elif [[ $header =~ $shebang_re ]]; then
echo "$f is *a* script and should still probably be chmodded"
fi
done
Still requires bash 4 due to globstar, but this could be removed if
desperately needed, by manually globbing at every directory level.
for f in * */* */*/* */*/*/*; do
...
done
=~ needs bash 3
testing indicates bash 2's `read` mangled the input, so that needs bash
3 too (or drop the elf binary check)
--
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User