Deleting Array Elements

Hi,

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?

Thanks,
Mike

By "DAY" do you mean literally "DAY" or is it something like "Sunday" or "Mon" or "MON"?
-- change the following code to meet your needs

days="SunMonTuesWedThuFriSat" 
cnt=0
while [ $cnt -lt ${#array ] ; 
do
      echo "$days" | grep -q "${array[cnt]}" 
      if [ $? -eq 0 ] ; then
           unset ${array[cnt]}
           break
      fi
done

Hi and thanks for the reply.

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[#]?

Mike

Hi,
As Jim stated You can loop over You array and unset the element when You hit it with a certain criterion, here's another example:

#!/bin/bash
arr=(qwe xc 3 DAY grok mok)
crit=DAY
cnt=0
for x in ${arr[@]}; do
	[ $x = $crit ] && unset arr[cnt] && break || ((cnt++))
done
echo ${arr[@]}

(I am using not so very portable bashism here...)
/Lakris