I have a single file shell script (BusyBox, no bash, ksh I believe) that I want to write a path to itself when run. I need #home to be replaced by home=/home. I have this:
var="/home"
#home
sed -i 's/#home/home=$var/g' /this/file.sh
When run it'll replace #home and the string in the sed line and the $var is not expanded:
var="/home"
home=$var
sed -i 's/home=$var/home=$var/g' /this/file.sh
This is my desired outcome:
var="/home"
home=/home
sed -i 's/#home/home=$var/g' /this/file.sh
I'm pulling my hair getting this to work. Any hints?
Answering myself this works as expected:
var="/home"
#home
sed -i "s|^#home|home=${var}/|g" m.sh