Quick Syntax Question

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
shadeclan
Posts: 61
Joined: 02 Jun 2011 11:29
Location: USA - Somewhere between Albany NY and Bennington VT

Quick Syntax Question

#1 Post by shadeclan » 29 Jun 2011 09:13

I've noticed a syntax in the functions section for batch information that I can't find any info on. For example, I noticed that comments like the created date are written:

Code: Select all

:$Created 20110639

Is this a form of code commenting because the dollar symbol is an illegal character in a label, similar to the double colon? If so, why is this same form used again on the same line?

Code: Select all

:$Created 20110628 :$Changed 20110629


Another question involving labels - is there any way to indent a label name? I ask in order to improve readability within a batch file.

Cleptography
Posts: 287
Joined: 16 Mar 2011 19:17
Location: scriptingpros.com
Contact:

Re: Quick Syntax Question

#2 Post by Cleptography » 29 Jun 2011 09:29

shadeclan wrote:Another question involving labels - is there any way to indent a label name? I ask in order to improve readability within a batch file.

Do you mean like tab it over... :?
Ummm I think you just hit the spacebar or tab keys. :roll:

Code: Select all

goto :hello
exit /b
   :hello
   echo;hello

Acy Forsythe
Posts: 126
Joined: 10 Jun 2011 10:30

Re: Quick Syntax Question

#3 Post by Acy Forsythe » 29 Jun 2011 10:28

Clept,

I think he meant "is it allowed?" and not "how to do it?" :)

And actually ":$Created" is a valid label. I've seen those comments before too and the best explainations I could come up with as educated guesses are:

1. Style
2. Self Parsing
3. Self parsing and Style

Code: Select all

@echo off
:$Created 06/29/2011

ECHO Results:
FOR /F "tokens=* delims=" %%A IN ('TYPE %~0 ^| FIND ":$"') DO (
echo %%A
exit /b
)


Code: Select all

Results:
:$Created 06/29/2011


Someone else might actually post a more valid reason :)

shadeclan
Posts: 61
Joined: 02 Jun 2011 11:29
Location: USA - Somewhere between Albany NY and Bennington VT

Re: Quick Syntax Question

#4 Post by shadeclan » 29 Jun 2011 12:25

Cleptography wrote:Ummm I think you just hit the spacebar or tab keys. :roll:
Ha ha. Very funny.

Acy Forsythe wrote:...And actually ":$Created" is a valid label. I've seen those comments before too and the best explainations I could come up with as educated guesses are:

1. Style
2. Self Parsing
3. Self parsing and Style
So, the dollar sign is a legal character in a label. Now, if someone can verify whether or not there is some significance to the :$ sequence, that would be great.

Assuming that the ampersand character signified the beginning of a new line, I tried to tab the label over and preface it with an ampersand, but it didn't work.

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Quick Syntax Question

#5 Post by Ed Dyreen » 29 Jun 2011 12:48

Code: Select all

@echo off

goto :skip
echo.ooops
!:skip Are u smoking a joint ?
echo.Yes, am I allowed ?

goto :skip
echo.ooops
&:skip Are u smoking a joint ?
echo.Yes, am I allowed ?

goto :skip
echo.ooops
|:skip Well, since you are dutch...
echo.Yes, you are allowed.
echo.Have fun ^!

goto :skip
echo.ooops
>:skip Have fun ^!
echo.Thanx :^)

pause
exit /b
Only one character is allowed before a label, any are allowed behind it :)

shadeclan
Posts: 61
Joined: 02 Jun 2011 11:29
Location: USA - Somewhere between Albany NY and Bennington VT

Re: Quick Syntax Question

#6 Post by shadeclan » 29 Jun 2011 13:08

Ed Dyreen wrote:

Code: Select all

@echo off

goto :skip
echo.ooops
!:skip Are u smoking a joint ?
echo.Yes, am I allowed ?

goto :skip
echo.ooops
&:skip Are u smoking a joint ?
echo.Yes, am I allowed ?

goto :skip
echo.ooops
|:skip Well, since you are dutch...
echo.Yes, you are allowed.
echo.Have fun ^!

goto :skip
echo.ooops
>:skip Have fun ^!
echo.Thanx :^)

pause
exit /b
Only one character is allowed before a label, any are allowed behind it :)

Well, Ed, are you coming to my rescue? Thanks as always! :lol:

That's strange. Before, when I put spaces in front of the colon, it didn't work but now it does - probably did something wrong somewhere else in the code that caused it to mess up. Regardless, that solves that issue.

Do you know if there is any significance to the dollar sign in front of the colon (:$)?

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Quick Syntax Question

#7 Post by jeb » 29 Jun 2011 14:50

Ed Dyreen wrote:Only one character is allowed before a label, any are allowed behind it

Where do you get this info from? 8) It's simply wrong :wink:

Code: Select all

goto :label1
  ;==;;,,,==,,,,     :label1
echo Ed said: Only one character is allowed before a label
goto :label2

                 :label2
echo Yes it works too


For a better explanation look at Re: Call a label as a variable

jeb

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Quick Syntax Question

#8 Post by Ed Dyreen » 29 Jun 2011 15:08


With character I mean ANY character, this won't work:

Code: Select all

@echo off

goto :skip
echo.ooops
     !:skip Are u smoking a joint ?
echo.Yes, am I allowed ?

goto :skip
echo.ooops
&&& >>> &:skip Are u smoking a joint ?
echo.Yes, am I allowed ?

goto :skip
echo.ooops
<<w<ghj|:skip Well, since it's legal where you live...
echo.Yes, you are allowed.
echo.Have fun ^!

goto :skip
echo.ooops
gvfcfh>:skip Have fun ^!
echo.Thanx :^)

pause
exit /b
It's not wrong, it's incomplete, but you are right jeb, as always. :)

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Quick Syntax Question

#9 Post by jeb » 29 Jun 2011 15:17

Btw. you can create a combi line, it is a legal label and a legal command line

[code]
call :label

<:label <nul echo This works
echo ###
[code]

output wrote:###
This works
###


jeb

Ed Dyreen
Expert
Posts: 1569
Joined: 16 May 2011 08:21
Location: Flanders(Belgium)
Contact:

Re: Quick Syntax Question

#10 Post by Ed Dyreen » 29 Jun 2011 15:28

:P That's cool, thanx jeb

Do you know of an example where this could be REALLY usefull ?

jeb
Expert
Posts: 1055
Joined: 30 Aug 2007 08:05
Location: Germany, Bochum

Re: Quick Syntax Question

#11 Post by jeb » 29 Jun 2011 15:56

Ed Dyreen wrote:Do you know of an example where this could be REALLY usefull ?


Yes, my BatchLibrary uses it to initialize itself.

Code: Select all

@echo off
REM 1. Prepare the BatchLibrary for the start command
call BatchLib.bat

REM 2. Start of the Batchlib, acquisition of the command line parameters, activates the code with the base-library
<:%BL.Start%

rem  Importing more libraries ...
call :bl.import "bl_DateTime.bat"
call :bl.import "bl_String.bat"

rem Use library functions
call :bl.String.Length result abcdefghij
echo len=%result%


And for some obscure tricks, Experiment with call and label

jeb

shadeclan
Posts: 61
Joined: 02 Jun 2011 11:29
Location: USA - Somewhere between Albany NY and Bennington VT

Re: Quick Syntax Question

#12 Post by shadeclan » 30 Jun 2011 06:54

Ed Dyreen wrote:
With character I mean ANY character, this won't work:

Code: Select all

@echo off

goto :skip
echo.ooops
     !:skip Are u smoking a joint ?
echo.Yes, am I allowed ?

goto :skip
echo.ooops
&&& >>> &:skip Are u smoking a joint ?
echo.Yes, am I allowed ?

goto :skip
echo.ooops
<<w<ghj|:skip Well, since it's legal where you live...
echo.Yes, you are allowed.
echo.Have fun ^!

goto :skip
echo.ooops
gvfcfh>:skip Have fun ^!
echo.Thanx :^)

pause
exit /b
It's not wrong, it's incomplete, but you are right jeb, as always. :)


Not quite, Ed. Multiple spaces will work.

Post Reply