Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Making an array in linux

I am trying to make an array that will have 84×28 values. The array should contain the number 1 repeated 28 times, followed by the number 2 repeated 28 times, and so on up until the number 84 repeated 28 times. I want the output to consist of 1 column and 84×28 rows, each for each number. Is there a way I can get started with this?

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Use nested for loops that append to the array.

#!/bin/bash

array=()
for i in {1..84}; do
    for j in {1..28}; do
        array+=($i)
    done
done

echo "${array[@]}"
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading