Now I use an ugly way to create arrays in shell, e.g.
ARG_ARRAY=(num1 num2 num3 num4 num5 num6 num7 num8 num9 num10)
Can this be more elegant ? like the C way, e.g.
ARG_ARRAY=num[10]
There are two types of arrays that we can work with, in shell scripts. The default array that's created is an indexed array. If you specify the index names, it becomes an associative array and the elements can be accessed using the index names instead of numbers. Notice the uppercase and lowercase letter a.
You can make an array of int s, double s, or any other type, but all the values in an array must have the same type. To create an array, you have to declare a variable with an array type and then create the array itself. Array types look like other Java types, except they are followed by square brackets ( [] ).
$ ARG_ARRAY=(num{1..10})
$ echo ${ARG_ARRAY[@]}
num1 num2 num3 num4 num5 num6 num7 num8 num9 num10
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