How to use bash substitution in a variable declaration

I am trying to declare a variable x with all characters from a..x . On the command line (bash), replacing a..x works without any ticks.

 $ echo {a..x} abcdefghijklmnopqrstu vwx 

But assigning the variable to the variable x={a..x} leads to {a..x} as a string. Only x=$(echo {a..x}) works.

Question: Is this the proper way of assignment, or do I need to do other things?

The main goal is to assign a sequence to an array, for example,

 disks=( $(echo {a..x}) ) 
+6
source share
1 answer

You can also use set (but be sure to keep the positional parameters if you need them):

 set {a..x} x=" $@ " 

For arrays, parenthesis expansion works directly:

 disks=( {a..x} ) 
+5
source

Source: https://habr.com/ru/post/904893/


All Articles