Shell variables in sed script

Viewed 83158

The sed command works as expected at the command prompt, but does not work in a shell script.

new_db_name=`echo "$new_db_name" | sed 's/$replace_string/$replace_with/'`

Why is that, and how can I fix it?

5 Answers

Guys: I used the following to pass bash variables to a function in a bash script using sed. I.e., I passed bash variables to a sed command.

#!/bin/bash                            
function solveOffendingKey(){

    echo "We will delete the offending key in file: $2, in line: $1"
    sleep 5
    eval "sed -i '$1d' $2"
}


line='4'
file=~/ivan/known_hosts
solveOffendingKey $number $file

Kind regards!

Related