I have a problem linking several variables in BATCH (cmd) with the "&" symbol

0

This is the problem:

set /a var1= %todo% & echo %linea%>>%exename%
set todo= %var1%'

What I want is that %var1% contain all the information above, and then pass it to %todo%

This is mostly that and the & is detected as if it were more than 1 command on a line.

    
asked by G44Gonzalo 15.10.2018 в 18:55
source

2 answers

0

When using the /a flag for arithmetic expressions that contain logical operations it is necessary to enclose the expression in double quotes ( "..." ):

set /a "var1=%todo% & %linea%>>%exename%"
set "todo=%var1%"

Here is a link with information and examples: link

    
answered by 15.10.2018 в 19:43
0

To see:

The problem is that %var1% is equal to 0 because the elements & and >> block it.

Sorry to put the image, the code does not put me as such, but anyway here is:

@echo off  
set exename= Ejemplo  

:loop  
set /p linea= Nueva linea (Escribe 0 para terminar.):  
if %linea%== 0 goto guardar  
set /a "var1=%todo% & %linea%>>%exename%"  
set todo= %var1%  
echo %var1%  
pause  
goto loop  
    
answered by 16.10.2018 в 17:43