简体   繁体   English

sed 未选择 bash 变量值

[英]sed is not picking bash variable value

I have a file named webroot with below contents:我有一个名为 webroot 的文件,其内容如下:

ROOT= .
#ROOT = Current Directory for Installers. Specify in double quotes.

I want to replace value foe first occurrence of ROOT with the path in double quotes, for which I created below script我想用双引号中的路径替换第一次出现的 ROOT 值,为此我在脚本下面创建

#!/bin/bash

ppath="$(dirname $(pwd))"

sed -i '0,/^ROOT.*/s/^ROOT.*/ROOT = \"\${ppath}\"/' webroot

grep -m1 ROOT webroot 

However, when I execute the script, I see below as output:但是,当我执行脚本时,我在下面看到 output:

ROOT = "${ppath}"

Updated the script to below, however same result:将脚本更新到下面,但结果相同:

#!/bin/bash

ppath="$(dirname $(pwd))"

sed -i "0,/^ROOT.*/s/^ROOT.*/ROOT = \"\${ppath}\"/" webroot

grep -m1 ROOT webroot 

Any suggestions, how this can be fixed?任何建议,如何解决?

Used below:下面使用:

sed -i "0,/^ROOT.*/s|^ROOT.*|ROOT = \"${ppath}"|" webroot

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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