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,972 of 68,980    |
|    JJ to R.Wieser    |
|    Re: echo a variable containing an & some    |
|    21 Nov 22 07:51:28    |
   
   From: jj4public@outlook.com   
      
   On Sun, 20 Nov 2022 21:04:33 +0100, R.Wieser wrote:   
   >   
   > Ive put a few lines of text ("hello&world", "&foo", "bar&") in a file,   
   > retrieved those lines and than called your ":sub" with it like this :   
   >   
   > for /f %%i in (words.txt) do call :sub %%i   
   >   
   > , but for some reason your ":sub" was not called for the first two (though   
   > no error or other output), but it was for the third/last line. IOW, I could   
   > not test it either ...   
      
   CALL would force the command line to be parsed and expanded twice.   
      
   On the second command line processing, the `%%i` is already expanded, so it   
   is or should be treated as a command separator. However, it seems that   
   there's a bug on the second command line processing, since it may cancel the   
   CALL command execution. Below is a simple demo of this bug.   
      
   @echo off   
   setlocal   
   set a=hello^&world   
   set b=%%a%%   
      
   rem output: abc "hello&world"   
   call echo abc "%b%"   
      
   rem expected output: hello&world   
   rem but since `%b%` is not quoted, after expansion,   
   rem the `&` should be treated as a command reparator.   
   rem but it cancels the whole command line.   
   call echo abc %b%   
      
   echo end   
      
   > I also tried a line (in the textfile) with an embedded doublequote. The it   
   > caused the "set /p" to wait for input again. And ofcourse the simple "echo   
   > %1" had no problems with it.   
      
   Chances are that, your SET /P is like this.   
      
   set /p a="%1" |
[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]
(c) 1994, bbs@darkrealms.ca