Forums before death by AOL, social media and spammers... "We can't have nice things"
|    alt.msdos.batch.nt    |    Fun with Windows NT batch files    |    68,980 messages    |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
|    Message 68,875 of 68,980    |
|    Herbert Kleebauer to Anton Shepelev    |
|    Re: Comma in an argument value    |
|    27 Nov 24 19:18:10    |
   
   From: klee@unibwm.de   
      
   On 27.11.2024 17:21, Anton Shepelev wrote:   
   > Hello, all.   
   >   
   > What does the following script:   
   >   
   > @ECHO OFF   
   > FOR /F "tokens=2,* delims= " %%A in ("%*") DO SET ARGS=%%B   
   > ECHO M:1:%1   
   > ECHO M:2:%2   
   > ECHO M:*:%ARGS%   
   >   
   > stored as test.bat invoked as   
   >   
   >> test.bat a "b,c" d e   
   >   
   > print:   
   >   
   > 1:a   
   > 2:"b,c"   
   > *:c" d e   
   >   
   > ?   
      
   Remove the @ECHO OFF then you can see the executed command:   
      
   FOR /F "tokens=2,* delims= " %A in ("a "b c" d e") DO SET ARGS=%B   
      
   FOR /F ["options"] %variable IN ("string") DO command [command-parameters]   
      
   Because the , is replaced by a space (why?), string becomes: a "b c" d e   
   Token 1:a   
   Token 2:"b   
    *:c" d e   
      
      
      
      
   > I expected it to print:   
   >   
   > 1:a   
   > 2:"b,c"   
   > *:d e   
      
   You get this if you use:   
      
   FOR /F "tokens=2,* delims= " %%A in ('echo %*') DO SET ARGS=%%B   
      
   > because the FOR /F loop should split the parameter by the   
   > space characer, and end up with all the token after the second   
   > one in the ARGS variable. Why is the comma treated as a command   
   > separator at some point?   
   >   
      
   --- SoupGate-DOS v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   
|
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca