[英]put variable into sed with bash
I try to use a variable in a sed of bash 我尝试在bash的sed中使用变量
I have this code : 我有这个代码:
read -p "Repertoire destination: " REP
echo $REP
sed -i 's/\$app\[\"bundle.root\"\] = \"\/var\/www\/\"\;/\$app\[\"bundle.root\"] = \"'$REP'\"\;/' /home/martialp/Documents/default.php
echo "Modification terminé"
I use simple quote like '$REP' but i have this error : 我使用像'$ REP'这样的简单引号,但出现此错误:
sed: -e expression n°1, caractère 80: option inconnue pour `s'
Your trouble is probably that $REP
contains slashes, but you're using /
to delimit the regular expression. 您的麻烦可能是
$REP
包含斜杠,但是您使用/
分隔正则表达式。 The easiest fix is to use some other character to delimit the regular expression, perhaps %
: 最简单的解决方法是使用其他一些字符来分隔正则表达式,也许是
%
:
sed -i 's%\$app\[\"bundle.root\"\] = \"\/var\/www\/\"\;%\$app\[\"bundle.root\"] = \"'$REP'\"\;%' /home/martialp/Documents/default.php
You can use any character that doesn't otherwise appear in the command; 您可以使用命令中不会出现的任何字符。 Control-A , for example, works well and is unlikely to appear in
$REP
. 例如, Control-A效果很好,不太可能出现在
$REP
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.