0

I have a JSON document like this -

{\"pp\": [0, 1024, 4, 1028, 8]}

Now how do I represent this [0, 1024, 4, 1028, 8] in a shell script?

something like below? does shell script have lists? And then how do I iterate that and print out the result in a shell script?

#!/bin/bash

PRIMARY_PARTITION=[0, 1024, 4, 1028, 8]

2 Answers 2

1
PRIMARY_PARTITION=(0 1024 4 1028 8)

Elements are ${PRIMARY_PARTITION[0]}, ${PRIMARY_PARTITION[1]}, etc. The entire array is "${PRIMARY_PARTITION[@]}".

Sign up to request clarification or add additional context in comments.

Comments

0
PRIMARY_PARTITION=(0 1024 4 1028 8)

for el in "${PRIMARY_PARTITION[@]}"; do echo "[$el]"; done

Comments

Your Answer

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