How to set a variable equal to user input without Set /P in simple batch script.

Hello,

I have a batch file where a default variable is set at the top..then the user is presented with an option to change the default.  If they hit "enter" it leaves default, however if they enter text, then it replaces the default with the text.  I can' get the variable to be set for some reason.  I am pretty new to BAT writing so I am sure its a simple syntax thing.  In the code below, I just need the line that says SET FTPHOST = %sel2% to work.  Right now, it doesn't change the vaule of FTPHOST from the default even when text is entered.  Thanks!

ED7
@echo off
set CDROM=d:
SET FTPHOST=192.168.1.2
SET FTPUN=administrator
SET FTPPW=password
SET FTPDIR=directoryname
 
setlocal enabledelayedexpansion
 
:_manualvariables
set /P sel1=Do you wish to change the defaults? [Y, (N)]:
if /I "%sel1%"=="n" goto :_header
if /I "%sel1%"=="y" goto :_sethost
goto :_header
 
:_sethost
set /P sel2=Enter the new IP Address [%FTPHOST%]:
   if not "%sel2"=="" goto else
     goto :_setrun
   goto endif
   :else
     SET FTPHOST  = %sel2%
   :endif

Open in new window

electricd7Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

SteveGTRCommented:
Change:

SET FTPHOST  = %sel2%

To:

SET FTPHOST=%sel2%

No spaces.

You may want to consider initializing setl1 to N or whatever you want the default to be prior to the first set /P statement.

There doesn't look to be an an immediate need for the enabledelayedexpansion. I'd recommend removing it and moving the setlocal statement prior to the FTP set commands.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
UbuntopCommented:
set /P sel2=Enter the new IP Address [%FTPHOST%]:
   if not "%sel2%"=="" goto else
     goto :_setrun
   goto endif
   :else
     set FTPHOST=%sel2%
   :endif

You are missing a % in your IF statement after Sel2.
Also remove the spaces in the Else portion around equals sign.
The above section works.
0
SteveGTRCommented:
Also, it is unnecessary to put the : before the goto lines:

goto :_header

Could read as:

goto _header
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.