I am using the below code for replacing a string inside a shell script.
echo $LINE | sed -e 's/12345678/"$replace"/g'
but it's getting replaced with $replace
instead of the value of that variable.
Could anybody tell what went wrong?
I am using the below code for replacing a string inside a shell script.
echo $LINE | sed -e 's/12345678/"$replace"/g'
but it's getting replaced with $replace
instead of the value of that variable.
Could anybody tell what went wrong?
I prefer to use double quotes , as single quptes are very powerful as we used them if dont able to change anything inside it or can invoke the variable substituion .
so use double quotes instaed.
Found a graceful solution.
If you want to interpret
$replace
, you should not use single quotes since they prevent variable substitution.Try:
assuming you want the quotes put in. If you don't want the quotes, use:
Transcript:
Just be careful to ensure that
${replace}
doesn't have any characters of significance tosed
(like/
for instance) since it will cause confusion unless escaped. But if, as you say, you're replacing one number with another, that shouldn't be a problem.you can use the shell (bash/ksh).
you can still use single quotes, but you have to "open" them when you want the variable expanded at the right place. otherwise the string is taken "literally" (as @paxdiablo correctly stated, his answer is correct as well)
Single quotes are very strong. Once inside, there's nothing you can do to invoke variable substitution, until you leave. Use double quotes instead: