home bbs files messages ]

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 67,530 of 68,980   
   JJ to Mark Ise   
   Re: for-loop cannot process braces   
   05 May 20 20:22:48   
   
   From: jj4public@vfemail.net   
      
   On Tue, 5 May 2020 11:53:37 +0200, Mark Ise wrote:   
   > Hello,   
   >   
   > I have been using a batch file with a for-loop for some years and today   
   > I figured out that it cannot process elements with braces.   
   >   
   > The code:   
   >   
   > for %%i in (%*) do (   
   > 	echo hallo   
   >  )   
   >   
   > Alternative:   
   > for %%i in ("%*") do (   
   >   
   > The problem:   
   > If arguments contain braces without spaces, the first version fails. The   
   > cmd-window closes without an error message.   
   >   
   > The alternative code fails if an argument contains spaces.   
   >   
   > I have tested the two versions and I think the problem is, that Windows   
   > sometimes adds quotes and sometimes not. I'm sure there is a way to   
   > process all sorts of arguments but I don't have more ideas and not the   
   > right key words to search for it.   
   >   
   > I have tested the following but it doesn't work:   
   > for %%i in ("%~*") do (   
   >   
   > Could an expert kick me to the right way please?   
      
   Quote the element by itself. In you case, a single batch parameter. Not the   
   whole parameters.   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca