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?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you want to interpret
$replace, you should not use single quotes since they prevent variable substitution.Try:
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.