I would like to expand a variable in Bash. Here's my example:
variable="{1,2,3}"
echo $variable
Expected output:
1 2 3
Actual output:
{1,2,3}
The expansion doesn't work because of the order in which bash performs command-line expansion. If you read the man page you'll see the order is:
Parameter expansion happens after brace expansion, which means you can't put brace expansions inside variables like you're trying.
But never fear, there's an answer! To store a list of numbers in a variable, you can use an array.
variable=(1 2 3)
echo "${variable[@]}"
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With