Discussion forum for all Windows batch related topics.
Moderator: DosItHelp
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#1
Post
by Ed Dyreen » 09 Jun 2011 03:18
☺
Linefeed not working in DisableDelayedExpansion ?
Code: Select all
echo.begin
set $LF=^
:: Two empty lines are neccessary
echo.setlocal DisableDelayedExpansion
setlocal DisableDelayedExpansion
set var1=this!$LF!works
set "var2=this!$LF!works too"
set var3=this%$LF%fails
set "var4=this%$LF%fails too"
set var5=this^%$LF%%$LF%works
set "var6=this^%$LF%%$LF%fails"
set ^"var7=this^%$LF%%$LF%works again"
echo.%var1%
echo.%var2%
echo.%var3%
echo.%var4%
echo.%var5%
echo.%var6%
echo.%var7%
echo.setlocal EnableDelayedExpansion
setlocal EnableDelayedExpansion
echo.%var1%
echo.%var2%
echo.%var3%
echo.%var4%
echo.%var5%
echo.%var6%
echo.%var7%
pause
exit
output:
Code: Select all
begin
setlocal DisableDelayedExpansion
this!$LF!works
this!$LF!works too
this
this
this
thisecho.this
setlocal EnableDelayedExpansion
this
works
this
works too
this
this
this
thisecho.this
Druk op een toets om door te gaan. . .
Am I doing something wrong ?
Last edited by
Ed Dyreen on 09 Jun 2011 05:49, edited 1 time in total.
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#2
Post
by jeb » 09 Jun 2011 05:44
Hmmm, it works as I expected
try this at the end
Code: Select all
setlocal EnableDelayedExpansion
echo(!var1!
echo(!var2!
echo(!var3!
echo(!var4!
echo(!var5!
echo(!var6!
echo(!var7!
jeb
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#3
Post
by Ed Dyreen » 09 Jun 2011 05:47
☺
in DisableDelayedExpansion ?
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#4
Post
by jeb » 09 Jun 2011 06:03
If you are in DisableDelayedExpansion, you need to use percent expansion, therefore the content is parsed in the special character phase, so you need to create your variable-content in a special way, so it works after two expansions.
Code: Select all
setlocal DisableDelayedExpansion
set lf=^
set var1=Line1^^^%LF%%LF%^%LF%%LF%Line2
set var1
echo ----
echo %var1%
The content of var1 is "Line1^<LF><LF>Line2" so this can be expanded with percent, so the ^<LF><LF> will be reduced to a single <LF>
jeb
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#5
Post
by Ed Dyreen » 09 Jun 2011 06:27
☺
Code: Select all
for %%! in ( @DelayedExpansion.Get.State ) do set "%%~!=echo. &set /p "?= Delayed Expansion is " <nul &if /i ["!"] neq [""] ( set /a DelayedExpansion.State = 0 &set /p "?=off" <nul ) else set /a DelayedExpansion.State = 1 &set /p "?=on" <nul"
::
%@DelayedExpansion.Get.State%
::
if /i ["%DelayedExpansion.Get.State%"] equ ["1"] setlocal DisableDelayedExpansion
::
%@DelayedExpansion.Get.State%
set $LF=^
:: Two empty lines are neccessary
set var1=Line1^^^%$LF%%$LF%^%$LF%%$LF%Line2
echo ----
echo %var1%
set \n=^^^%$LF%%$LF%^%$LF%%$LF%
set var1=Line1%\n%Line2
echo ----
echo %var1%
pause
exit
Still not working
Code: Select all
Delayed Expansion is on
Delayed Expansion is on----
Line1
Line2
----
Line1
Druk op een toets om door te gaan. . .
Last edited by
Ed Dyreen on 09 Jun 2011 06:42, edited 1 time in total.
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#6
Post
by jeb » 09 Jun 2011 06:41
Your code expands the content three times, therefore you need the obvious string of
Code: Select all
set \n=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
jeb
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#7
Post
by Ed Dyreen » 09 Jun 2011 06:46
^^^%$LF%%$LF%^%$LF%%$LF%
^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
^^^^^^^^^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
I just imitate your thinking jeb because this is all quite new to me
Is this logical ?
-
jeb
- Expert
- Posts: 1055
- Joined: 30 Aug 2007 08:05
- Location: Germany, Bochum
#8
Post
by jeb » 09 Jun 2011 06:57
Nearly ...
But your last line is not correct
This should be (obviously
)
This works for four expansion cycles
Code: Select all
set $lf=^
set n4=^^^^^^^^^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%
set var1=Line1%n4%Line2
set var2=%var1%
echo %var2%
jeb
-
Ed Dyreen
- Expert
- Posts: 1569
- Joined: 16 May 2011 08:21
- Location: Flanders(Belgium)
-
Contact:
#9
Post
by Ed Dyreen » 09 Jun 2011 06:59
☺
Yahoo, it works ! Look at me I'm a dinosaur
Code: Select all
set ^"\n=^^^^^^^%$LF%%$LF%^%$LF%%$LF%^^^%$LF%%$LF%^%$LF%%$LF%"
This should be (obviously
)
Have to crunch it down, cause I'm not much of a mathematic
Code: Select all
^^^%$LF%%$LF%
^%$LF%%$LF%
^^^^^^^%$LF%%$LF%
^%$LF%%$LF%
^^^%$LF%%$LF%
^%$LF%%$LF%
^^^^^^^^^^^^^^^%$LF%%$LF%
^%$LF%%$LF%
^^^%$LF%%$LF%
^%$LF%%$LF%
^^^^^^^%$LF%%$LF%
^%$LF%%$LF%
^^^%$LF%%$LF%
^%$LF%%$LF%