works step by step on command line but not in script

Hi all,
The following script is fine when I work via command line

m=1
c=0
while [ $c = 0 ]
do
echo $m
gnokii --getsms IN $m > out.txt;
m=`expr $m + 1`;
cat out.txt >> message_log;
############
read first crap< <(sed -n '/Text:/{n;p;}' out.txt);
read message< <(sed -n '/Text:/{n;p;}' out.txt);
if [ $first != "02" ]; then
cat out.txt
fi
#############
SIZE=`wc -c out.txt | tr -d ' out.txt'`
if [ $SIZE == 0 ]; then 
echo 'time to exit';
c=`expr $c + 1`;
fi  
done

but when run via a shell script I get the error message:

/usr/local/bin/mc_smsread.sh: line 18: syntax error near unexpected token `<'
/usr/local/bin/mc_smsread.sh: line 18: `read first crap< <(sed -n '/Text:/{n;p;}' out.txt);'

Why does it work on command line but not within the loop?

Here is an example out.txt file that is written and used:

1. Inbox Message (read)
Date/time: 30/11/2007 18:17:03 
Sender: O2-UK Msg Center: +447802000332
Text:
O2 Rewards: Get rewarded with 10% back on all your top-ups - simply text REWARD to 50202 free to join. Call 313 opt. 4 free for info & terms. Stop SMS call 2220

Any help gratefully received,

Adam

I believe you need the script to be executed by a shell
that supports process substitution
(I suppose you're using such shell when you're executing it manually).

Try making the first line like this:

#!/path/to/bash

ksh93 and zsh supports that syntax also.

perfect thank you