sed:-e expression#1,char 23:`s'的未知选项

Ale*_*lek 6 sed

我正在尝试使用sed来使用bash脚本更新配置文件.我在脚本运行正常的上面有一个类似的sed命令.我似乎无法弄清楚为什么这会破坏:

sed -i.bak \
    -e s/"socketPath:'https://localhost:9091'"/"socketPath:'/socket'"/g \
    $WEB_CONF
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?

Wal*_*r A 17

引号和双引号引起问题.您正在使用它们来查看字符串中的斜杠.在sed中,您可以使用另一个分隔符,例如#.

sed -e 's#socketPath:https://localhost:9091#socketPath:/socket#g' \
$WEB_CONF
Run Code Online (Sandbox Code Playgroud)


ara*_*aer 5

在模式中转义斜线或使用其他分隔符,如下所示:

sed -i.bak \
-e s%"socketPath:'https://localhost:9091'"%"socketPath:'/socket'"%g \
$WEB_CONF
Run Code Online (Sandbox Code Playgroud)