sed adds multiple lines with special characters in a bash file

I've been trying to understand this for a while now, but I need to phone the experts.

sed & # 39; / # algoscreens / a 
& # 39; $ {coinname} & # 39; = "screen -dmS & # 39; $ {coinname} & # 39; bash $ STRATUM_DIR / run.sh
& # 39; $ {coinsymbol}. $ {coinalgo.conf} & # 39; "
& # 39; $ {coinname} & # 39; stop = & # 39; screen - Strate & # 39; $ {coinname} 'quit & # 39; & # 39;

who needs to read

a5a = "screen -dmS a5a bash $ STRATUM_DIR / run.sh a5a"
a5astop = -X -S screen left a5a

Then I have

    sed & # 39; / # algocommands / a  startstop _ & # 39; $ {coinname} & # 39; () {
cmd = $ 1 
box $ cmd in 
stop) $ {coinname} & # 39; stop ;; 
start) $ {coinname} & # 39; ;; 
to restart)
& # 39; $ {coinname} & # 39; stop 
to sleep 1 
& # 39; $ {coinname} & # 39; 
;; 
esac 
}  Stratum

who needs to read

startstop_a5a () {
cmd = $ 1
box $ cmd in
stop) $ a5astop ;;
start) $ a5a ;;
to restart)
$ a5astop
to sleep 1
$ a5a
;;
esac
}

finally

sed & # 39; / # shift / a 
& # 39; $ {coinname} & # 39;) startstop _ & # 39; $ {coinname} & # 39; $ cmd ;; & # 39; stratum

who needs to read

a5a) startstop_a5a $ cmd ;;

I continue to have a bad substitution error.