Code: Select all
>nul copy /A nul+nul "!$defines!.TMP"
:: (
for /f "usebackq" %%? in (
"!$defines!.TMP"
) do set "!$defines!=%%?"
:: )
>nul del /f /q "!$defines!.TMP"
echo. This%$Sub%Works
Code: Select all
This→Works
Moderator: DosItHelp
Code: Select all
>nul copy /A nul+nul "!$defines!.TMP"
:: (
for /f "usebackq" %%? in (
"!$defines!.TMP"
) do set "!$defines!=%%?"
:: )
>nul del /f /q "!$defines!.TMP"
echo. This%$Sub%Works
Code: Select all
This→Works
Code: Select all
@echo off
:: (
for /f "usebackq" %%? in (
"%~nx0"
) do set "sub=%%?"
:: )
echo. This%sub%Works
REM there is a hex 1A after this line. Doesn't paste into forum
Code: Select all
E:\batch files\SUB>getsub.bat
This→Works
Code: Select all
:: → @echo *** WHAT ???
@set /p "SUB=" <"%~f0"
@set "SUB=%SUB:~3,1%"
@echo this %SUB% works
Code: Select all
*** WHAT ???
this → works
Code: Select all
C:\>set "eotsub=.^D.^Z.^D^Z"
C:\>set eotsub
eotsub=.♦.
C:\>set /p "eotsub="
.^D.^Z.^D^Z
C:\>set eotsub
eotsub=.♦.→.
Code: Select all
^
::
@echo off
set /p "sub="<"%~f0"
echo. This%sub%Works
That is easily solved with a substring operation.aGerman wrote:Edit: No, sorry. This is not what it seems to be. The caret is part of the variable
You can say that againLiviu wrote:The (cmd) world would be a better more predictable place, had you never asked that question
Code: Select all
@echo off
setlocal enableDelayedExpansion
set /p "sub="<"%~f0"
set "sub=%sub:~0,1%"
set sub
echo(
echo embeddedecho works
echo(
echo multiplesecho are ok
echo(
echo expanded%sub%echo fails
echo(
echo escaped^Echo is stripped
echo(
for %%A in (hellogoodbye) do @echo %%A
echo(
if 1==1 (echo true 1echo true 2) else (echo false 1echo false 2)
echo(
if 1==0 (echo true 1echo true 2) else (echo false 1echo false 2)
echo(
for /f %%A in ('echo 1echo 2') do echo for /f direct: %%A
for /f %%A in ('echo 1%sub%echo 2') do echo for /f immediate expansion: echo %%A
for /f %%A in ('echo 1!sub!echo 2') do echo for /f delayed expansion: echo %%A
Code: Select all
sub=→
embedded
works
multiples
are ok
expanded→echo fails
escapedEcho is stripped
hello
goodbye
true 1
true 2
false 1
false 2
for /f direct: 1
for /f immediate expansion: echo 1→echo
for /f delayed expansion: echo 1→echo
dbenham wrote:Code: Select all
echo(
echo expanded%sub%echo fails
echo(Code: Select all
expanded→echo fails
dbenham wrote:That is easily solved with a substring operation.aGerman wrote:Edit: No, sorry. This is not what it seems to be. The caret is part of the variable
Liviu wrote:P.S. If you save your or aGerman's code as say ctrlz.cmd, then the added bonus is that "type ctrlz.cmd" will output nothing at all. That must be the grandfather of all copy protections
Actually no. I was referring to the ability of Ctrl-Z to function like the & operator. It no longer separates commands if it is the result of a variable expansion.Liviu wrote:dbenham wrote:Code: Select all
echo(
echo expanded%sub%echo fails
echo(Code: Select all
expanded→echo fails
Think you meant "expanded%sub%echo works".
That would be possible were it not for the fact, the last/first line I already use to embed jscriptSquashman wrote:I know this may sound kind of hokey but why not just have that character as the last character in your batch file
Code: Select all
@set @a=0 /* Enable Jscript comment, must be first line in batch !
...
rem :: Disables Jscript comment, must be last line in batch ! */
Very useful indeedaGerman wrote:However, it causes crazy effects in a batch code I wonder if it could be useful ...
Code: Select all
::'@cscript //nologo //e:vbscript "%~f0" & exit /b
WScript.Echo "Example of a hybrid VBS / batch file"
Code: Select all
::'This is the batch portion
::' @echo off
::'
::'Test if GOTO works
::' goto :'TestGoto
::' echo goto failed & exit /b
::'
:'TestGoto
::' echo goto succeeded
::'
::'Now test if CALL works
::' call :'TestCall
::' exit /b
::'
:'TestCall
::' echo call worked
::' cscript //nologo /e:vbscript "%~f0"
::' exit /b
' The remainder is VBScript
WScript.Echo "Another more complicated example of a hybrid VBS / batch file"
dbenham wrote:Very useful indeedaGerman wrote:However, it causes crazy effects in a batch code I wonder if it could be useful ...
Now we can embed VBScript in a batch file without resorting to a temporary file.
...
We can even make the batch portion complex if we are willing to put up with the nasty ::' prefix. Batch labels need to be written as :'Label