我试图执行以下脚本以从文件中获取当前路径字符串并将其传递给在下一个命令中查找和替换。直接在主机服务器中运行时它工作正常,但是当尝试从 jenkins 构建步骤执行时,我遇到了找不到文件的失败。
错误:sed:无法读取 test.txt:没有这样的文件或目录
预期的结果是在“currentPath”存在的地方用“newPath”更新“test.txt”文件
代码 :
user="testuser"
host="remotehost"
newPath="/testpath/"
filetoUpdate="./test.txt" # this is a file
ssh -o UserKnownHostsFile=/dev/null -o StrictHostKeyChecking=no -i ~/.ssh/id_rsa ${user}@${host} "currentPath="$(sed -n '/^PATH='/p $filetoUpdate | cut -d'=' -f2)" ; echo "currentPath was "$currentPath"" ; sed -n 's|$currentPath|$newPath|g' $filetoUpdate"