Here's what I get when I enter those snippets on the command line:
prompt> $(for i in {1..5}; do echo $i; done)
1: command not found
prompt> echo $(for i in {1..5}; do echo $i; done)
1 2 3 4 5
In the first case, the syntax itself is valid, but since you don't have any command or variable assignment, bash is just doing the command substitution, and then attempting to parse the output of the command substitution as a command. It's exactly as if you'd done this:
prompt> 1 2 3 4 5
1: command not found
Since you're just getting a hang on this command, and no output, then there must be something else going on that's most likely not related to bash itself.
In the second case, for me anyway, it works. The numbers get echoed out on a single line because you didn't quote the command substitution, so the newlines are just treated as delimiters, and it's essentially identical to:
echo 1 2 3 4 5
If you quote the command substitution, you get this:
prompt> echo "$(for i in {1..5}; do echo $i; done)"
1
2
3
4
5
Bottom line: Your loop syntax is valid, as is using it inside a command substitution. Just don't expect the loop's output to be interpreted as a valid bash command. That is, unless you actually have a an executable named 1 in your PATH.
forloop without the$(...)?>prompt you get if you just typewhileand hit enter? Have you checked your aliases withalias?1: command not foundand the second should just output the numbers 1 through 5 on one line.PS4=':${BASH_SOURCE}:$LINENO+' bash -x -l -ito log the commands they run (and which file and line every such command comes from) is a pretty good place to start.