sh 如何将变量的值附加到文件中 sh 双引号多行
sh how to Append variable's value to file into sh double quoted multiline
我需要将字符串追加到文件中。该字符串由一些前缀+变量组成。
这是在使用 Groovy 语法的 Jenkins 管道中,因此读取变量值的唯一方法是使用多行双引号 sh.
sh """
...some lines of code affecting the same scope...
echo "sdk.dir=${ANDROID_HOME}" > local.properties
...some lines of code affecting the same scope...
"""
实际:
WorkflowScript: 101: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "$5" or bracket the value expression "" @ line 101, column 49.
echo "sdk.dir=${ANDROID_HOME}" > local
您是否尝试像提到的错误一样使用斜杠转义 $ 符号?
您还使用了相同的双引号,请尝试将“sh”命令替换为三重单引号,并像现在一样在 shell 重定向中使用双引号。
或者你可以转义整个表达式的最后一个选项:
\\”表示\\”
我需要将字符串追加到文件中。该字符串由一些前缀+变量组成。 这是在使用 Groovy 语法的 Jenkins 管道中,因此读取变量值的唯一方法是使用多行双引号 sh.
sh """
...some lines of code affecting the same scope...
echo "sdk.dir=${ANDROID_HOME}" > local.properties
...some lines of code affecting the same scope...
"""
实际:
WorkflowScript: 101: illegal string body character after dollar sign;
solution: either escape a literal dollar sign "$5" or bracket the value expression "" @ line 101, column 49.
echo "sdk.dir=${ANDROID_HOME}" > local
您是否尝试像提到的错误一样使用斜杠转义 $ 符号?
您还使用了相同的双引号,请尝试将“sh”命令替换为三重单引号,并像现在一样在 shell 重定向中使用双引号。
或者你可以转义整个表达式的最后一个选项:
\\”表示\\”