在 sed 命令中使用变量将返回 sed: -e 表达式 #1, char 7486: 未终止的 `s' 命令

问题描述 投票:0回答:1

所以在詹金斯我正在做以下事情

 cert = sh(returnStdout: true, script: "cat cert.json")
 sh "sed -i '0,/content:.*/s//content: $cert/g' example.yaml"

因此,当 sed 命令替换

$cert
并将
/g' example.yaml
放在新行上时,这会破坏 sed 命令,从而导致

sed:-e 表达式 #1,字符 7486:未终止的 `s' 命令

如何解决此问题,以便

/g' example.yaml
不在新行上

bash jenkins sed jenkins-pipeline sh
1个回答
0
投票

通过在末尾添加 .trim() 解决了它

© www.soinside.com 2019 - 2024. All rights reserved.