Solved batchfile - SET command adds a extra space after its set

August 21, 2012 at 02:55:02
Specs: Windows XP
Hey all..again.. :P

this code:

IF /i "%choice%"=="1" SET choice=variable1

now if i echo it variable1 has a space

echo %choice% - shows "variable1 " when i want "variable1"

does that make sense?

I was going to go down the line of:

echo>>vari.txt %choice:~0,5% - which i guess will "cut off" the spaces..
set /p newvari1= < vari.txt
echo %newvari1%

BUT each variable im setting is not the same length & if i dont have to enter more lines in my script..that would be good?!?


See More: batchfile - SET command adds a extra space after its set

Report •


#1
August 21, 2012 at 04:00:26
We tried it,but no extra space.

BTW,it not good idea to test and change a variable like you did.


====================================
Life is too important to be taken seriously.

M2


Report •

#2
August 21, 2012 at 04:35:03
Thanks for trying maybe im just doing something wrong...
from the start this is what i have...

@ECHO OFF
SETLOCAL ENABLEEXTENSIONS
SETLOCAL ENABLEDELAYEDEXPANSION
SET root_dir=\\serverroot

MODE CON:COLS=50 LINES=16
COLOR 8F
:agency_choose
TITLE Searching in - %root_dir%
ECHO [1] A
ECHO [2] B

SET choice=
SET /p choice=Which Agency:
IF "%choice%"=="" SET choice =%choice:~0,2%
IF /i "%choice%"=="1" SET choice=A && GOTO userid_search_start
IF /i "%choice%"=="2" SET choice=B && GOTO userid_search_start


after I do the rest...searching I im displaying user is located here..
%root_dir%\%choice%\%user_dir%

its annoying me but hey, might just be one of those things...

thanks again !!


Report •

#3
August 21, 2012 at 15:04:03
✔ Best Answer
IF /i "%choice%"=="1" SET choice=A && GOTO userid_search_start

The Set command as shown is doing exactly what you coded, it is setting choice to A with a trailing space. Try .....SET choice=A&& goto.......etc... i.e. eliminate the space.


Please come back & tell us if your problem is resolved.


Report •

Related Solutions

#4
August 22, 2012 at 01:32:47
Yeah that worked without the spaces ^_^

Thanks guys


Report •

#5
August 22, 2012 at 03:13:28
Wahine nailed it.

While we're at it...

IF "%choice%"=="" SET choice =%choice:~0,2%

If the var is NUL [empty] you can't get a substr.

IF /i "%choice%"=="1"

No point in /i because nums have no case.


====================================
Life is too important to be taken seriously.

M2


Report •


Ask Question