2 ms·
Yup, which you could also write as eval echo {1..$var} . The second argument's variable is being interpolated as if it's a quoted string, before it gets passed
by 0xbadcafebee 4y ago
Yup, which you could also write as eval echo {1..$var} . The second argument's variable is being interpolated as if it's a quoted string, before it gets passed to eval, so eval is actually seeing "{1..1234}" and not doing the interpolation itself (because it wouldn't, because the variable isn't valid in a range). This should prevent the need for a subshell and the second echo call.
With an array:
var=12
declare -a array=()
eval "array=( {01..$var} )"
echo "${array[@]}"
# 01 02 03 04 05 06 07 08 09 10 11 12