0

I have TeamCity build step in command line which is executed on Windows 7.
We should escape variables in script with double percent and etc.

How to escape next construction for using it in TC step?

set word=\\
set Build=%Build:\=!word!%
set enter=\n
set Build=%Build:""=!enter!%
Mofi
  • 46,139
  • 17
  • 80
  • 143
pic0
  • 491
  • 1
  • 6
  • 15
  • I do not understand you question. Could you please elaborate and provide an example. – Squashman Nov 29 '16 at 19:48
  • Yes. When we use inner script variables at TC step we should escape them in %%var%%. How I can escape "!" in string "set Build=%Build:\=!word!%" for replacing data in it? – pic0 Nov 29 '16 at 20:03
  • Please [edit] your question and add **1st** a [mcve] and **2nd** what do you get *versus* what do you expect to get from your code. Maybe `set Build=!Build:\=%word%!` could work? – JosefZ Nov 29 '16 at 23:38

1 Answers1

0

I guess you refer to teamcity buildstep If you want to escape the percent sign from being expanded one way is to double the percentsign which is also a method of delayed expansion. The exclamation mark is the the replacement char for the percent sign when using setlocal EnableDelayedExpansion

It's not clear what you are trying to accomplish with your code.

In cmd the \n replacement won't work.

If your intention is to simply pass the % unchanged through an echo in cmd the doubling should suffice. If delayed expansion is enabled you may have to escape the exclamation mark with a caret ^!

This code :

@Echo off&setlocal EnableDelayedExpansion
Set Build=C:\Test\Build""secondline
set word=\\
set LF=^


rem The TWO empty lines above are required
rem See http://stackoverflow.com/a/5642300/6811411

set Build2=%Build:\=!word!%
set Build2=%Build2:""=^^!LF^^!%
Echo Build =%Build%
Echo Build2=%Build2%

Produces this output here:

Build =C:\Test\Build""secondline
Build2=C:\\Test\\Build
secondline