There seem to be a few misconceptions at work here:
First, about $(ls) . This is a device called "process substitution" and it works like this: the command inside the brackets is executed, its output is taken and put on the commandline. Then the resulting commandline is executed. In your case the command is "ls" but it could be any simple or cmplicated command:
echo "foo $(ls | grep '^a') bar"
This will first execute "ls", then feed its output to "grep '^a'" (which will filter out all filenames starting with "a"). Suppose there are two files, "afile1" and "afile2". These strings will be put on the command line replacing the original command, resulting in:
echo "foo afile1 afile2 bar"
and this command will finally be executed. You can use this always instead of a normal string.
The for-loop in shell languages works quite differently than in other languages. Normally there are 4 elements to a for-loop: a variable, a starting value, an increment and an endcondition. The variable is loaded with the starting value, then the loop is executed each time incrementing the loop variable, until the endcondition is finally reached, upon which the loop is terminated:
for( i=1; i<=10; i++ )
this means: the loop variable is "i" and is loaded initially with the value 1 ("i=1"). Each iteration of the loop the value is incremented by 1 ("i++", which is an abbreviation for "i=i+1") and each iteration the end condition ("i<=10") is checked. Once i becomes bigger than 10, the loop terminates.
A shell for-loop works similar, but it is given a list of values to set the variable to:
for X in a b c d e f g
means: in the first iteration set variable "X" to value "a", in the second to "b", and so on, until the last, "g", is reached, upon which the loop terminates.
Combine this with the above and you see:
for filename in $(ls)
"filename" is the name of the variable to be used and the list of values is the output of "ls", which produces a list of filenames.
Finally:
The "type" of a file is - unlike in DOS or Windows - not determined by its extension. In Windows every file with the extension ".EXE" is executable, everything else is not. In Unix there are the rights (issue "ls -l" to see them on the leftmost column), which determine if a file is executable or not. If the "x"-flag is set the OS will try to execute it, if not, then not.
It is true that most name files conventionally according to their respective types: ".sh" for shell scripts, ".txt" for text files and so on. But this is just convention! There is no hard rule to do so and if you name a shell script "script.txt" it will still get executed if you have set the execute-flag (via the "chmod"-command). This may not be a god idea, because it will be confusing, but technically there is nothing that keeps you from doing it.
The "type" of a file is a different concept in UNIX and it is controlled via the file "/etc/magic". This file contians rule definitions what constitutes a certain file type based on the respective files contents. For instance, there could be a rule that a file starting with "#! /bin/sh" in the first line is a shell script. execute
file /path/to/file.in.question
and the file command will figure out the file type based on consulting the rules in "/etc/magic". You can even extend the ruleset with your own rules and file types.
I hope this helps.
bakunin