How do I test the first char of each line in an array

Hi folks,

I am self-learning as I can

I have a script that has read a file into an array.
I can read out each line in the array with the code:

for INDEX in {0..$LENGTH}   ## $LENGTH was determined at the read in
do
  echo "${data[$INDEX]}"
done

What I need to do is test the first char of each line so I can branch out for processing.
In essence, the psudo-code looks like this:

for INDEX in {0..$LENGTH}   ## $LENGTH was determined at the read in
do
  If the first char of "${data[$INDEX]}" = " " then skip
   or
  If the first char of "${data[$INDEX]}" = "!" then skip
   else
    Capture the current line into a second array to be referenced later in
       the script
done

But I've searching not seen anything I can understand
Thanks for any help

Similar question here...

As you say you are self-learning i won't give you a solution, but will tell you instead where you can find the solution:

See in the manual of your shell (i suppose it to be either bash or ksh - they are identical in this regard) under "Variable expansion" or "Parameter expansion". There are basically two devices:

${var#<regexp>} / ${var##<regexp>}
${var%<regexp>} / ${var%%<regexp>}

one subtracts "<regexp>" from the beginning, one from the end of the contents of "$var". You can even nest these expressions and feed the one as regexp into the other:

${var%${var#<regexp>}}

Check this out, experiment a little and eventually you will find a solution to your problem.

I hope this helps.

bakunin