You are not logged in.
Pages: 1
Because it seems I cant:
if exist c:\ (
goto :myLabel
:mylabel
)prints:
) was unexpected at this time.I can workaround this with subroutine but it's strange.
I have no problems with going to labels outside the IF.
http://www.facebook.com/npocmaka
Offline
There are two different problems here.
1) A GOTO inside of brackets breaks the bracket context (and stops a FOR-Loop)
if 1==1 (
goto :next
echo never reached
:next
echo After the label
) ELSE (
echo Why I can see this?
)Outputs
After the label
Why I can see this?As you can see the ELSE isn't effective anymore after invoking the GOTO
2) Labels are a bit strange inside of brackets
Labels in brackets use always two lines
- The primary line is the label, here is also a :: Label allowed
- The secondary line (after a label) must be a VALID statement or and label (but not a :: comment), an empty line or a closing bracket isn't valid here
In the secondary line are also the special characters active like "&|>"
(
:NormalLabel & echo this will not be executed
:SecondaryLine & echo This will be executed
)As you can see, it's all obvious ![]()
jeb
Offline
IT'S ALIVE!
..I mean it works with two labels.Thanks a lot :-) .
And it's not so obvious.I still do not understand why with two labels the bracket context works.But anyway it works .
http://www.facebook.com/npocmaka
Offline
Mix the character & with labels are confusing:
(
:Label1 & echo line1
:Label2 & echo line2
)prints:
line2But:
(
:Label1
echo line1
:Label2
echo line2
)prints:
line1
line2Offline
@Carlos - Oooh, that is pure evil. I like it! ![]()
Offline
Long time ago there was a discussion about labels inside barckets.
Nested for loop recursing directories
and here
SO: windows batch file with goto command not working
And there exists a more evil construct.
for %%a in (1 2 3) DO (
:label1 ^
::label2
:label3
::Label4 ^
NeverEver^
(^ AlwaysWorks echo %%a)
)It will show the numbers 1 to 3 (obviously) ![]()
Ok the code it's a bit obfuscated, but a little bit fun must be. ![]()
Btw. I'm happy that I recover my lost sample, as it's the only known way (for me),
to remove a single token form the beginning of a line.
jeb
Last edited by jeb (06 Nov 2012 09:38)
Offline
Pages: 1