简体   繁体   中英

Creation of brace sequence not working in bash

I must create a sequence of numbers using the number of elements that an list has.

arr1=(1 2 3 4 5 6)

I thought about the following expression in order to do so, but it is now working.

echo {0..$(expr ${#arr1[*]} - 1)} {0..5} # output

The correct output should be:

0 1 2 3 4 5

Could anyone explain me why I do not get the correct values?

You just need to add an eval :

$ a=(1 2 3 4 5 6)
$ eval echo {0..$(expr ${#a[*]} - 1)}
0 1 2 3 4 5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM