Page 1 of 1
Quick Syntax Question
Posted: 29 Jun 2011 09:13
by shadeclan
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:
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.
Re: Quick Syntax Question
Posted: 29 Jun 2011 09:29
by Cleptography
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.
Code: Select all
goto :hello
exit /b
:hello
echo;hello
Re: Quick Syntax Question
Posted: 29 Jun 2011 10:28
by Acy Forsythe
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
)
Someone else might actually post a more valid reason
Re: Quick Syntax Question
Posted: 29 Jun 2011 12:25
by shadeclan
Cleptography wrote:Ummm I think you just hit the spacebar or tab keys.
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.
Re: Quick Syntax Question
Posted: 29 Jun 2011 12:48
by Ed Dyreen
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
Re: Quick Syntax Question
Posted: 29 Jun 2011 13:08
by shadeclan
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!
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 (:$)?
Re: Quick Syntax Question
Posted: 29 Jun 2011 14:50
by jeb
Ed Dyreen wrote:Only one character is allowed before a label, any are allowed behind it
Where do you get this info from?
It's simply wrong
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 variablejeb
Re: Quick Syntax Question
Posted: 29 Jun 2011 15:08
by Ed Dyreen
☺
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.
Re: Quick Syntax Question
Posted: 29 Jun 2011 15:17
by jeb
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
Re: Quick Syntax Question
Posted: 29 Jun 2011 15:28
by Ed Dyreen
That's cool, thanx jeb
Do you know of an example where this could be
REALLY usefull ?
Re: Quick Syntax Question
Posted: 29 Jun 2011 15:56
by jeb
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 labeljeb
Re: Quick Syntax Question
Posted: 30 Jun 2011 06:54
by shadeclan
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.