(The links I'm posting are for bash, but most of what they say applies to ksh too.)
1) Please use [code][/code]
tags around your code, to preserve formatting and to improve readability. Do NOT use quote tags, as they don't protect whitespace.
2) Don't read lines with for
. Also, cat is usually unnecessary for reading from single files in modern shells.
3) $(..) is highly recommended over `..`
is, in my experience, notoriously unreliable when it comes to detecting text files. It often mistakenly detects simple text as being, say, a lisp script. It has something to do with the way it parses the beginning of the file to determine it's "magic" type. At the very least try using the -i option and parse the mime-type info instead.
5) Instead of using grep, try generating a simple list of file names, then loop through the list, testing the output of file
for each one directly. Perhaps something like this:
while read file ; do
if [[ $( file -i "$file" ) =~ plain ]]; then
echo "$file is a plain text file"
P.S. I don't think you'll find many people here who see "geek" as being derogatory. Indeed, "geek pride" is on the rise, as subjects like gaming and comics that were once nerdy are now mainstream, and it's becoming clearer to everyone that those who really
know the tech are the ones who hold the reins.