Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

Line continuation

May
13
0
I have a problem with line continuation and alias.
It seems to happen only when using aliases.
This code will show the error:
Code:
@Echo OFF
Alias SetVar=DO F in /L %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 (Set %%F)
REM The following 2 lines should act as if its a single line
SetVar A=10 B=20 C=30 ^
D=1 E=2
Echo  A=%A B=%B C=%C D=%D E=%E
The output is:
A=10 B=20 C=30 D= E=
But D and E should also be set

- Heinz Saathoff
 
I can confirm that observation and am also puzzled by it. The help does not say anything about line continuation not applying to command lines with an alias command. Actually, it is not true of all aliases, so there is something special about the case above. The following batch file runs without any problem. [Note that in all the code pasted here, the back quotes are lost. All the alias definitions are back-quoted.]

[TCC33.00.20 | C:\commands\bat]
type test.btm
@echo off
alias setvar=echo Command tail: %$
setvar a=1 b=2 c=3 ^
d=4 e=5

[TCC33.00.20 | C:\commands\bat]
Command tail: a=1 b=2 c=3 d=4 e=5

It looks as though it has something to do with the DO command. Here's another case. It is the same as the one above but with the DO command after the ECHO command. Even the ECHO fails to get the full list of arguments (and the "d=40 e=50" on the continuation line is treated as a new command, which invokes my alias D to get a directory listing)

[TCC33.00.20 | C:\commands\bat]
type test.btm
@echo off
alias setvar=echo Command tail: %$ & do f in /l %$ (echo %f)
setvar a=1 b=2 c=3 ^
d=4 e=5

[TCC33.00.20 | C:\commands\bat]
Command tail: a=1 b=2 c=3 ^
a=1
b=2
c=3

Volume in drive C is Windows Serial number is a879:820d
0 bytes in 0 files and 0 dirs
326,911,557,632 bytes free

The DO command interferes with the processing of the continuation of the command line.
 
I have a problem with line continuation and alias.
It seems to happen only when using aliases.
This code will show the error:
Code:
@Echo OFF
Alias SetVar=DO F in /L %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 (Set %%F)
REM The following 2 lines should act as if its a single line
SetVar A=10 B=20 C=30 ^
D=1 E=2
Echo  A=%A B=%B C=%C D=%D E=%E
The output is:
A=10 B=20 C=30 D= E=
But D and E should also be set

Alias expansion is performed before line continuations are processed. (It's behaved this way since version 1.)

If alias expansion occurred afterwards, you wouldn't be able to define aliases that contained line continuations. So - a tradeoff that hopefully solves more problems than it causes.
 
It' not only alias. I changed the code to GOSUB
and the error is still there. Here's the GOSUB code:
Code:
@Echo OFF
REM The following 2 lines should act as if its a single line
Gosub SetVar  A=10 B=20 C=30 ^
D=1 E=2
Echo  A=%A B=%B C=%C D=%D E=%E
Quit

:SetVar [A B C D E F G H]
  DO F IN /L %A %B %C %D %E %F %G %H
    Set %F
  ENDDO
RETURN
BTW, it's version 31 of TCC
 
As I'm not a fan of extremely long lines of source code,
nor am I a fan of continuing a line on the next line,
I break the code down to logical lines.

Example;
Code:
@setlocal
@echo off

COMMENT
     _x64: 1
   _admin: 1
_elevated: 1

TCC  30.00.18 x64   Windows 10 [Version 10.0.19044.2965]
ENDCOMMENT

set _a=10
set _b=20
::
:: Set _test as an equation
::
set _test=%%_a eq 10 .or. %%_b eq 10
echo Does %_test?
if (%_test) (echo Yes) else (echo No)
::
:: Adjust values of _a and _b
::
set _a=11
set _b=21
echo Does %_test?
if (%_test) (echo Yes) else (echo No)
endlocal

After running the above;
Code:
Does 10 eq 10 .or. 20 eq 10?
Yes
Does 11 eq 10 .or. 21 eq 10?
No

Ref: https://jpsoft.com/forums/threads/avoid-continued-lines-in-source-code.11516/

Joe
 
It' not only alias. I changed the code to GOSUB
and the error is still there. Here's the GOSUB code:
Code:
@Echo OFF
REM The following 2 lines should act as if its a single line
Gosub SetVar  A=10 B=20 C=30 ^
D=1 E=2
Echo  A=%A B=%B C=%C D=%D E=%E
Quit

:SetVar [A B C D E F G H]
  DO F IN /L %A %B %C %D %E %F %G %H
    Set %F
  ENDDO
RETURN
BTW, it's version 31 of TCC

Not reproducible here in v31, 32, or 33. (Except that the non-existent %F, %G, and %H GOSUB parameters don't get set, as expected.)
 
Code:
@Echo OFF
Alias SetVar=DO F in /L %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 (Set %%F)
REM The following 2 lines should act as if its a single line
SetVar A=10 B=20 C=30 ^
D=1 E=2
Echo  A=%A B=%B C=%C D=%D E=%E
The output is:
A=10 B=20 C=30 D= E=
But D and E should also be set

- Heinz Saathoff
No line continuation needed...
Code:
@Echo OFF
Alias SetVar=DO F in /L %%1 %%2 %%3 %%4 %%5 %%6 %%7 %%8 %%9 (Set %%F)
REM Create a variable for the variables
set theVars=A=10 B=20 C=30 D=1 E=2
SetVar %theVars
Echo  A=%A B=%B C=%C D=%D E=%E
The output is:
Code:
 A=10 B=20 C=30 D=1 E=2

Ref: https://jpsoft.com/forums/threads/line-continuation.12246/post-70481

Joe
 
Back
Top