A
A
AirFlare2021-12-17 20:33:42
cmd/bat
AirFlare, 2021-12-17 20:33:42

How to properly escape a string?

Greetings! I've been suffering for the second hour already... How to properly escape the contents of the LINE variable?

set s=1

if %s% == 1 (

set LINE=block_image_update(map_partition("product_a"), package_extract_file("product.transfer.list"), "product.new.dat.br", "product.patch.dat") ||	abort("E2001: Failed to update product image.");

echo %LINE% >> file

)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
W
wisgest, 2021-12-18
@AirFlare

In general, the question is not so simple.

Original answer ignoring the fact that the commands are in parentheses
В данном случае можете заменить | на ^^^|:
set LINE=block_image_update(map_partition("product_a"), package_extract_file("product.transfer.list"), "product.new.dat.br", "product.patch.dat") ^^^|^^^|	abort("E2001: Failed to update product image.");

— экранируются | для set и ещё раз экранируются | и уже ^ для echo.

In this case, you can use delayed variable expansion and escape |and ):
setlocal enabledelayedexpansion

set s=1
if %s% == 1 (

set LINE=block_image_update(map_partition("product_a"^), package_extract_file("product.transfer.list"^), "product.new.dat.br", "product.patch.dat"^) ^|^|	abort("E2001: Failed to update product image."^);

echo !LINE! >> file

)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question