Comparison in bat file cmd

1

I'm trying to make a comparison using the IF () where I compare the current month and assign its name but I can not print the results of the variables

This is the code I have

@echo off
SET FOLDER=%Date:~0,2%-%Date:~3,2%-%Date:~6,4%-%time:~0,2%
set mes=%date:~3,2%
@echo %mes%
set nombre="nombre"


IF %mes% == 10 (
    %nombre%="Octubre"  
    @echo %nombre%
)
if %mes% == 11 (
    %nombre%="Noviembre"
    @echo %nombre%
)

pause

At the end he gives me a message like this:

  

"" name "" is not recognized as an internal or external command, program or executable batch file.   "name"

I hope you can help me

    
asked by Sharly Infinitywars 30.10.2018 в 15:37
source

1 answer

1

The main problem is that the environment variables in the batch files are "expanded" when a line is analyzed. In the case of blocks delimited by parentheses, the entire block counts as a "line" or command.

One possibility is that the echo or the use you make of the variable do it outside the blocks if :

set mes=%date:~3,2%
set nombre="nombre"

IF %mes% == 10 (
    set nombre="Octubre"  
)

Another possibility is to use setlocal enabledelayedexpansion and access the variable by ! , which forces the evaluation of it:

setlocal enabledelayedexpansion

set mes=%date:~3,2%
set nombre="nombre"

IF %mes% == 10 (
    set nombre="Octubre"  
    @echo !nombre!
)

Source: Variables in batch file not being set when inside IF?

    
answered by 30.10.2018 / 17:17
source