DO /L and quoted arguments?

Aug 23, 2010
688
9
I just stumbled upon a problem. I wanted to process some strings passed as parameters, but the result was somewhat unexpected.
I've reduced the issue to this Simple Test Case:
Code:
SET i=0
DO EXT IN /L .sh ".bad sh"
  SET i=%@EVAL[%i+1]
  IFF "%@LEFT[1,%[EXT]]" == "." THEN
    ECHO "%[EXT]"
  ENDIFF
ENDDO
ECHO Did %i runs.
Contrary to the expectation, the cycle runs 3 times and only display one extension. (The latter is not actually suprising, considering the former.)

Is this considered normal behavior?
 

samintz

Scott Mintz
May 20, 2008
1,557
26
Solon, OH, USA
The parameters following DO x IN /L are strings, not filenames. Each parameter will be assigned in sequence, from left to right, to the loop control variable on consecutive passes through the loop. /L will not treat double quotes as delimiters; use /Q if you want to pass arguments with embedded white space.
Code:
do e in /l .sh ".bad sh" (echo %e)
.sh
".bad
sh"

do e in /q .sh ".bad sh" (echo %e)
.sh
".bad sh"
 
Aug 23, 2010
688
9
There's no /Q option for TCC/LE
Code:
[~\Documents\Bugs\TCC]$ "do-_Q-stc.btm"

TCC LE  14.00.9 x64   Windows 7 [Version 6.1.7601]
Did 0 runs.
And RT doesn't unquote parameters.
 

samintz

Scott Mintz
May 20, 2008
1,557
26
Solon, OH, USA
You could use @unquote to unquote the parameters.
Code:
do e in /q .sh ".bad sh" (echo %@unquote[%e])
.sh
.bad sh
 
Aug 23, 2010
688
9
Yes, I know. It's just extra work when I already explicitly know that paramerets may have been quoted.
And it is @UNQUOTES[] rather than @UNQUOTE[], since the latter destroys inner quoting of the string.