sed to add a line to a file

Hi,

I am trying to add a line to a file using sed .

tmp1:

aaaa
Hello
bbbb
Hello

I need to add "testing" after the first match of Hello. So the output should be

aaaa
Hello
testing
bbbb
Hello

and the line to be added will be a variable

using command line this works:

echo $line
testing

cat tmp1 | sed '1,/Hello/ {/Hello/a\
'$line'
}'

but the same if i execute using a script it fails with error,

sed: -e expression #1, char 68: unknown command: `-'

Are you sure the error is with the script as given above? It doesn't have 68 char, but only 31... On top, it executes flawlessly on my system.
Please post entire script, and its execution log (set shell's -x option).

The given script can work, but a few comments.
$line should be "$line" otherwise the shell expands it. (Dependent on the value in $line it can even cause the reported error message.)
If there is Hello in the very first line, the given script will find the first AND the second Hello.
No need for cat. <file lets the shell open it and connects sed's stdin to it.

<file sed ...

sed can also open the file (and even many files) itself. Here are all corrections:

sed '
# if Hello is found
   /Hello/{
# append $line
    a\
'"$line"'
# in a loop read the remainder of the file
    :L
    n
    bL
  }
' file