#1 22 May 2013 20:07

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 329

shift inside parentheses (and one side enclosed nested variables)

this does not work:

@echo off
for /l %%c in (1=1=5) do (
	echo --%1--
	shift
)
echo --%1--

here's the output:

C:\>shift_test.bat ich ni san shi go roku
--ich--
--ich--
--ich--
--ich--
--ich--
--roku--

i.e. it looks like something that need delayed expansion (except that delayed expansion does not help).Same for all cases when shift is inside brackets if, just brackets ...


The only that I've found so far that workarounds this is:

@echo off
for /l %%c in (1=1=5) do (
	call echo --%%1--
	shift
)
echo --%1--

and the output:

C:\>shift_test.bat ich ni san shi go roku
--ich--
--ni--
--san--
--shi--
--go--
--roku--

it's a little bit slow ...but works.
Any other ideas?

edit:
call %%1 works in similar way as call %%%nested_variable%%% .I have not tested this with for loop yet but I will...


additional ~ accessing arguments without shift:

setlocal enableDelayedExpansion
set /a counter=0
for /l %%x in (1, 1, 9) do (
 set /a counter=!counter!+1
 call echo %%!counter! 
)
endlocal

Last edited by npocmaka (07 Nov 2013 14:31)


http://www.facebook.com/npocmaka

Offline

#2 22 May 2013 20:22

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 329

Re: shift inside parentheses (and one side enclosed nested variables)

And a test with call and one side enclosed variables (can I call them in this way?) :

@echo off

set nested=Matryoshka
call echo %%%1%%

for  %%N in (nested) do (
	call echo %%%%N%%
)

and the result of my test:

C:\>test.bat nested
Matryoshka
Matryoshka

or

@echo off
call call echo %%%%%1

output:

C:\>test.bat 2 Matryoshka
Matryoshka

smile

Last edited by npocmaka (23 May 2013 09:30)


http://www.facebook.com/npocmaka

Offline

#3 23 May 2013 14:39

jeb
Member
From: Germany
Registered: 19 Nov 2010
Posts: 99

Re: shift inside parentheses (and one side enclosed nested variables)

It's the normal behaviour, as percent variables and parameters are expanded while the block is parsed.

Your second sample could be smaller

@echo off
call echo %%%1

test.bat 3 shichi hatchi

Output

hatchi

Offline

#4 24 May 2013 08:24

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 329

Re: shift inside parentheses (and one side enclosed nested variables)

.

Last edited by npocmaka (24 May 2013 08:27)


http://www.facebook.com/npocmaka

Offline

#5 15 Jul 2013 21:38

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 329

Re: shift inside parentheses (and one side enclosed nested variables)

'tunneling' is working also with shift (which was expected):

@echo off

shift & echo %1
goto :eof

C:\test>test.bat  Eins zwei
Eins

Last edited by npocmaka (15 Jul 2013 22:45)


http://www.facebook.com/npocmaka

Offline

#6 15 Jul 2013 22:14

jeb
Member
From: Germany
Registered: 19 Nov 2010
Posts: 99

Re: shift inside parentheses (and one side enclosed nested variables)

npocmaka wrote:

2.SHIFT /n is good at math  yikes

That would be unexpected!
BUT I can't reproduce it.

And even your sample seems not to be prove it.
The "zwei" is missing, not the "vier".

It seems that the SHIFT takes only the first number after the slash.

Btw. Warum verwendest du deutsche Zahlen wenn du aus Bulgarien kommst?
Why are you using german numbers when you are from bulgaria?

Offline

#7 15 Jul 2013 22:42

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 329

Re: shift inside parentheses (and one side enclosed nested variables)

jeb wrote:
npocmaka wrote:

2.SHIFT /n is good at math  yikes

That would be unexpected!
BUT I can't reproduce it.

And even your sample seems not to be prove it.
The "zwei" is missing, not the "vier".

It seems that the SHIFT takes only the first number after the slash.

Btw. Warum verwendest du deutsche Zahlen wenn du aus Bulgarien kommst?
Why are you using german numbers when you are from bulgaria?

My mistake.Every thing after the first number is  ignored.But didn't delete my post fast enough.

Last edited by npocmaka (25 Oct 2013 12:41)


http://www.facebook.com/npocmaka

Offline

#8 15 Jul 2013 23:02

npocmaka
Member
From: Bulgaria
Registered: 03 Dec 2009
Posts: 329

Re: shift inside parentheses (and one side enclosed nested variables)

jeb wrote:

Btw. Warum verwendest du deutsche Zahlen wenn du aus Bulgarien kommst?
Why are you using german numbers when you are from bulgaria?

I don't know...For diversity I suppose

Last edited by npocmaka (25 Oct 2013 12:41)


http://www.facebook.com/npocmaka

Offline

Board footer

Powered by FluxBB