bash - Simplest way to expand a variable in a shell script -


what simplest way forcibly expand variable in script such this:

#!/bin/some path=/nobackup/ sed -i "39s/.*/$path/" cluster.sh 

or easiest shell script language expand variables without problems? there force expand options?

the variable expanded; problem value contains characters sed treats syntax. sed sees command

39s/.*//backup// 

one solution when trying build sed command dynamically know ahead of time characters variable include, , use different delimiter in sed command.

sed -i "39s|.*|$path|" cluster.sh 

another solution is, if can control value of $path, pre-escape problem characters.

path='\/backup\/' sed -i "39s/.*/$path/" cluster.sh  # 39/.*/\/backup\// 

Comments