Note that the sed one-liner suggested in the comments (sed -i "s/^\\(TEXT_BLOCK=\\).*/\\1$replacement/" path) won't work for some values of $replacement.
E.g., if the variable contains a /, you'd get:
replacement="Hello/"
echo 'TEXT_BLOCK=init' | sed -e "s/^\\(TEXT_BLOCK=\\).*/\\1$replacement/"
# → sed: -e expression #1, char 30: unknown option to `s'
Albeit the OP's question is tagged with sed, I'd suggest to write some perl -wpe one-liner instead, to have a more robust script, and given perl is a fairly standard dependency, it should probably be available on the OP's target machine.
To write one such script, you could just rely on the Perl operators s/// and BEGIN{ }.
Proof of concept:
#!/usr/bin/env bash
subst() {
re="$1"
str="$2"
perl -wpe 'BEGIN {$re=shift @ARGV; $str=shift @ARGV;}; s/$re/$str/g;' "$re" "$str"
}
# Usage example
echo $'TEXT_BLOCK="init"\nEnd.' | subst '^TEXT_BLOCK=.*$' 'TEXT_BLOCK="3$/"'
# will print:
# TEXT_BLOCK="3$/"
# End.
Note that this can easily be adapted to the sed -i use case:
#!/usr/bin/env bash
subst_i() {
fil="$1"
re="$2"
str="$3"
perl -i -wpe 'BEGIN {$re=shift @ARGV; $str=shift @ARGV;}; s/$re/$str/g;' "$re" "$str" "$fil"
}
# Usage example
echo $'TEXT_BLOCK="init"\nEnd.' > data.txt
subst_i data.txt '^TEXT_BLOCK=.*$' 'TEXT_BLOCK="3$/"'
cat data.txt
sed -i "s/^\\(TEXT_BLOCK=\\).*/\\1$replacement/" path, double quotes and$var.$replacement; try e.g. withreplacement="/"; so I'd suggest using a Perl one-liner or so, instead ofsedhere.