简体   繁体   中英

php sed exec will not change $variable in a file

I'm working on a php script that uses sed to change a value in a file to whatever the $value is in the php script. Here is my code:

$value = red;

$color_change = exec('sed -i '.escapeshellarg('s/color-name=.*/color-name=$value/g')." /home/user/color.props");
echo "$color_change";

Instead of sed changing color-name in the file to red it literally changes it to $value instead. So I get color-name=$value in the file instead of color-name=red. It is as if sed isn't seeing the $value = red part in my script.

Use " around the string instead of '

" allows variable substitution where as ' puts the value in as written.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM