I try to use a variable in a sed of bash
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 :
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. 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
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.