Reputation: 859
I want to do this:
for i in {1.."$((2**3))"}; do echo "$i"; done
But that would output {1..8}
, which I want to execute, not output.
How to?
Upvotes: 1
Views: 203
Reputation: 7801
You can't do in like that in bash, brace expansion happens before variable does. A c-style for loop can be an alternative.
for ((i = 1; i <= 2**3; i++)); do printf '%d ' "$i"; done
... Or if you really want to do the brace expansion use eval
which is not advised to use but it is the only way...
eval echo {1..$((2**3))}
See the local bash manual for the order of expansion PAGER='less +/^EXPANSION' man bash
and the online manual (thanks to @Freddy
) https://www.gnu.org/software/bash/manual/html_node/Shell-Expansions.html
See eval
in the local bash manual PAGER='less +/^[[:blank:]]*eval\ ' man bash
Upvotes: 1
Reputation: 15624
You could to use seq
instead of range braces:
for i in $(seq 1 $((2**3))); do echo "$i"; done
Upvotes: 2