I'm experiencing a strange behaviour with a Windows batch script when I want to read a value by prompting the user. Here is my script:
echo off
set VALUE=toto
set _VALUE=
set /p _VALUE=Enter the value or leave blank to accept default (%VALUE%):
if [%_VALUE%] NEQ [] ( set VALUE=%_VALUE% )
set _VALUE=
echo "%VALUE%"
If I keep the default, here is what I get, as expected:
...>myscript.cmd
Enter the value or leave blank to accept default (toto):
"toto"
But if I enter a new value, here is what I unexpectedly get:
...>myscript.cmd
Enter the value or leave blank to accept default (toto): titi
"titi "
Why is there a blank space after
titi
, as seen in"titi "
?What should be the syntax to simply get
"titi"
as expected?
Thanks in advance for your help!