howto add line as a first line into a non empty file

Hi

Trying to do like this :

echo "$variable1\n $(cat file.txt)"

but it only adds one time. When I run this cmd again with different variable it only replaces line of variable1.

How to add constantly line into first line in file ?

one way:

echo "$variable" > tmpfile
cat oldfile >> tmpfile
mv tmp oldfile
sed -ie '1i\
'$variable'\
' file.txt

thx but how to implement this here