I am writing a BASH shell script. I have an array that will contain IN ANY ORDER the following elements: DAY 8D MO NS.
I would like to erase the element DAY, but since the order of the elements in the array are random, I will not know which element # DAY is (ie it's not as simple as saying unset array[#], as I won't know what # is). How can I do this?
I don't think I did a good enough job explaining myself.
I have the following array:
rrdhcp78-122:L0 msb65$ test_array=(8D DAY MO)
rrdhcp78-122:L0 msb65$ echo ${test_array[@]}
8D DAY MO
I understand that if I wanted to remove the element "DAY" from "test_array" I would type: "unset $test_array[1]". However, in my script the elements of "test_array" will be in a random order. Therefore "DAY" won't always be the second element.
Given a random "test_array", how do I determine which element number (#) "DAY" corresponds to so that I can remove it: unset $test_array[#]?