Artificial intelligent assistant

insert multiple lines to script with sed i'm trying to insert variables before specific line in my script. this is the code that i'm using: var1=$(echo "database1=") var2=$(echo "database2=") var3=$(echo "database3=") sed -i "/#variables/i \ $var1\ $var2\ $var3" /data1/create_database i expect that `create_database` be like this after i run above command: database1= database2= database3= #variables but i get this result: database1= database2= database3= #variables tried few ways nothing worked. what should i do?

You don't need command substitutions to set your variables:


var1="database1="
var2="database2="
var3="database3="


I think you need single quotes to add newlines, but it looks quite ugly if you quote your variables with double quotes. The double quotes are needed if your variables contain space characters:


sed -i '/#variables/i\
'"$var1"'\
'"$var2"'\
'"$var3" /data1/create_database


With GNU sed you could simply add a few newlines:


sed -i "/#variables/i$var1\
$var2\
$var3" /data1/create_database

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 4545fe22d8169556b3dcd7e31a7befaf