I have a script that restores db dump. As a parameter a database name is passed to this script. In a dump there is a following line:
ALTER DATABASE `previosDbName` CHARACTER ... ;
I have to change previosDbName
to a value, passed as a parameter. I try to use sed
, but it does not work.
Here is a script:
echo $3
export updateValue="ALTER DATABASE \`$3\`"
echo $updateValue
sed -i 's/ALTER DATABASE `\(.*\)`/${updateValue}/' $4
Here how I run it:
./test.sh dbP dbN medi_6_0 full_path_to_test.sql
The output of the script tells us, that updateValue
is a correct one:
medi_6_0
ALTER DATABASE `medi_6_0`
But the result string:
${updateValue} CHARACTER ...;
Instead of:
ALTER DATABASE `medi_6_0` CHARACTER ...;
I've also tried to use double quotes, but it did not help:
sed -i 's/ALTER DATABASE `\(.*\)`/"${updateValue}"/' $4
Update: Solution offered by @Sundeep helped:
sed -i 's/ALTER DATABASE `\(.*\)`/'"${updateValue}"'/' $4
None of solutions described in: How to use variables in a command in sed? Helped. As most of solutions (did not check all of them), offered in this topic.