0

I wanted to initialize a large array in bash, preferably using MATLAB style array initialization. For e.g. I want something similar to following

Declare an array with elements ranging from 0 to 1000 with the gap of 5

array=0:5:1000

I know you can achieve that in a for loop as following

for i in {0..1000..5}
do
done

But same does not work in the following case

array={0..1000..5}

syntax error: operand expected (error token is "{0..1000..5}")

1 Answer 1

2

In order to make an array assignment, you need to wrap the brace expansion in ().

array=({0..1000..5})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.