简体   繁体   中英

A literal string containing escape slashes on groovy

My groovy script calls other commands via vagrant. One of those commands is to echo some quotes on a file within docker.

The goal is, so that within the container, i want to have BB_GENERATE_MIRROR_TARBALLS = "1" . Now to do this on a bash script, i would need something like this:

BB_GENERATE_MIRROR_TARBALLS = \\"1\\"

The issue manifests itself when i have to escape double quotations on the groovy as well.

If i call vagrant("echo BB_GENERATE_MIRROR_TARBALLS = \\\\\\"1\\\\\\" >> ${yoctoDir}/build/conf/local.conf" on my groovy file, the outcome on the local.conf will be BB_GENERATE_MIRROR_TARBALLS=1 (without quotes).

The correct way to do this would be to include an extra backslash on both sides (3 for the groovy, 1 for the bash script), however when i do that, groovy doesnt run and gives me syntax errors.

What would be the correct way to insert this literal string( BB_GENERATE_MIRROR_TARBALLS=\\"1\\" ) on the groovy?

In groovy you can do the following:

def my_var = /BB_GENERATE_MIRROR_TARBALLS = "1"/
echo my_var >> ${yoctoDir}/build/conf/local.conf

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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