Just Another Comment Format

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Just Another Comment Format

#1 Post by Meerkat » 08 Aug 2015 08:24

Since this is DosTips, I think (almost) everything Batch/DOS is already discovered. :cry:
BTW, I will still post... :D

Code: Select all

@echo off

)| This is a comment...
)| Format: Close parenthesis, then pipe, then the comment...
)| So this will be commented.

echo HelloWorld!!!
pause


Output

Code: Select all

HelloWorld!!!
Press any key to continue . . .


Meerkat

Squashman
Expert
Posts: 4488
Joined: 23 Dec 2011 13:59

Re: Just Another Comment Format

#2 Post by Squashman » 08 Aug 2015 11:45

Will fail inside a code block.

OperatorGK
Posts: 66
Joined: 13 Jan 2015 06:55

Re: Just Another Comment Format

#3 Post by OperatorGK » 08 Aug 2015 12:24

You don't need pipe here.

Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Re: Just Another Comment Format

#4 Post by Meerkat » 09 Aug 2015 02:10

Squashman wrote:Will fail inside a code block.


Yeah, I know...

OperatorGK wrote:You don't need pipe here.


I 'm sorry I do not understand, what do you mean?

Meerkat

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Just Another Comment Format

#5 Post by foxidrive » 09 Aug 2015 03:55

The pipes aren't needed. It's an interesting discovery though.

Code: Select all

@echo off

) This is a comment...
) Format: Close parenthesis, then pipe, then the comment...
) So this will be commented.

echo HelloWorld!!!
pause

Meerkat
Posts: 89
Joined: 19 Jul 2015 02:27
Location: Philippines

Re: Just Another Comment FormatS

#6 Post by Meerkat » 09 Aug 2015 06:02

Oh... yeah.... :)

...just adding :mrgreen:

Code: Select all

@echo off

) This is a comment...
)|This is a comment...
)<This is a comment...
)&This is a comment...
)>This is a comment...
)(This is a comment...


echo HelloWorld!!!
pause


Output:

Code: Select all

HelloWorld!!!
Press any key to continue . . .


Meerkat

npocmaka_
Posts: 517
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Just Another Comment Format

#7 Post by npocmaka_ » 09 Aug 2015 06:50

interesting and could be confusing at some situations : http://ss64.com/nt/goto.html

though these are not working:

Code: Select all

))
)"
):


Other standard delimiters also can be used:

Code: Select all

)=
);
),

Aacini
Expert
Posts: 1932
Joined: 06 Dec 2011 22:15
Location: México City, México
Contact:

Re: Just Another Comment Format

#8 Post by Aacini » 09 Aug 2015 09:48

npocmaka_ wrote:interesting and could be confusing at some situations : http://ss64.com/nt/goto.html


That is a confusing example not just because the output, but because the way that it is generated:

Code: Select all

@echo off
if A equ A (
        GOTO :EXAMPLE_LABEL
        :EXAMPLE_LABEL
    rem
) else (
    echo You didn't expected to see this,did you?
)

The GOTO command break the IF and start to search for the label from the next parsed block of code, that is the code placed after the IF! The label is not found and it is searched again from the beginning of the file. When the label is reached, the execution continue with no code block pending, so the ") else (" is just ignored and the next ECHO executed. I like this!!! :P

I posted a similar convoluted example in SO, but it is related to duplicate labels:

Code: Select all

@echo off

set var=1
if %var% equ 1 (

:NEXT
   if %var% neq 1 goto NEXT
   echo This appear first time:  var=%var%
   set var=2
   goto NEXT

:NEXT
   echo This appear second time: var=%var%

)

Antonio

dbenham
Expert
Posts: 2461
Joined: 12 Feb 2011 21:02
Location: United States (east coast)

Re: Just Another Comment Format

#9 Post by dbenham » 09 Aug 2015 10:17

Yep... At StackOverflow I have another example to add to the collection: (Windows batch) Goto within if block behaves very strangely.

My answer talks about how ) can function as a comment if there is not an active (


Dave Benham

Post Reply