Welcome!

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

SignUp Now!

CALL ... SETLOCAL/ENDLOCAL ... DO ... alias expansion glitch?

May
12,846
164
@niros deserves credit for discovering this one. I just whittled it down. I don't know if it's a bug but it sure is strange. Below (third snippet), the DO command works before the CALL to DUMMY.BTM and it fails afterwards.

Code:
v:\> type dummy.btm
setlocal
endlocal

Code:
v:\> type test.btm
setlocal

echo First try:
which utility:
which myfindstr
do line in /P `echo foo | myfindstr foo` (echo %line)

call dummy.btm

echo ^r^nSecond try:
which utility:
which myfindstr
do line in /P `echo foo | myfindstr foo` (echo %line)

endlocal

Code:
v:\> test.btm
First try:
utility: is an alias : v:\a b
myfindstr is an alias : "utility:\findstr.exe"
foo

Second try:
utility: is an alias : v:\a b
myfindstr is an alias : "utility:\findstr.exe"
TCC: V:\test.btm [13]  Unknown command "utility:\findstr.exe"
 
P.S., I'm using global aliases. I thought at first that it had something to do with the LFN in the alias. It doesn't. This version fails similarly.

Code:
v:\> type test.btm
setlocal

echo First try:
which s32:
which myfindstr
do line in /P `echo foo | myfindstr foo` (echo %line)

call dummy.btm

echo ^r^nSecond try:
which s32:
which myfindstr
do line in /P `echo foo | myfindstr foo` (echo %line)

endlocal

Code:
v:\> test.btm
First try:
s32: is an alias : c:\Windows\system32
myfindstr is an alias : "s32:\findstr.exe"
foo

Second try:
s32: is an alias : c:\Windows\system32
myfindstr is an alias : "s32:\findstr.exe"
TCC: V:\test.btm [13]  Unknown command "s32:\findstr.exe"
 
Tried your example right above and yes, same result here.

The only exception was, if I loaded the aliases with tcstart.btm ("your" aliases were added to my "normal" global aliases list file), THEN it worked (I assume tcstart.btm is executed through the call command too, so the aliases remain, or not?). However: in that case I had only one global aliases list in use, which was loaded through tcstart.btm ...

Maybe the following from the help could also have an influence? ...

ENDLOCAL command - Restore data saved by SETLOCAL
If you have both local and global aliases or functions, ENDLOCAL will only restore the local list (that was saved by SETLOCAL).
 
Last edited:
News :-)

If I replace your code line:

Code:
do line in /P `echo foo | myfindstr foo` (echo %line)

for the 2nd try with:

Code:
do line in /P (echo foo | myfindstr foo) (echo %line)

it works!

Difference/inconsistency with consecutive back quotes in /P parsing? Or is the PIPE relevant here?
At least I have no idea why the command grouping here is successful and consecutive back quotes not.
 
Last edited:
Good observation, @Alpengreis. Still, the CALL to a BTM with SETLOCAL/ENDLOCAL is leaving its mark on the calling BTM.
 

Similar threads

Back
Top