I have an array made of:
old_array=("color" "red" "shape" "circle" "vote" "10")
(alternating key/values)
I need to build a new_array so that:
echo $new_array[color]
red
echo $new_array[shape]
circle
and so on.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You need bash’s associative arrays.
First, declare the variable as an
Associative Arraywithdeclare -A:Then set values in the array like you would do with regular arrays:
You can convert your
old_arraytonew_arraylike this:You can also write new_array directly: