0

Scenario

I want that If user enters a value, I get host name and If user do not enter any value then I just echo default path.

Problem Statement

After adding these conditions in if else I am getting echo is off if user enters a values.

How can i resolve this?

SET /P USER_INSTALL= Installation Path : 
@echo:
if "%USER_INSTALL%"=="" ( echo "------Default path------") else (
ECHO %USER_INSTALL%
FOR /F "usebackq" %%i IN (`hostname`) DO SET HOST=%%i
ECHO %HOST%)
4
  • 1
    change SET /P USER_INSTALL= Installation Path : to SET /P "USER_INSTALL=Installation Path: " see no spaces around equsl sign. also don't use echo: to echo a blank line, use either echo/ or echo(. Commented Aug 16, 2017 at 12:42
  • 2
    Possible duplicate of Windows Batch Variables Won't Set Commented Aug 16, 2017 at 12:46
  • 1
    Also, it's batch, not bash Commented Aug 16, 2017 at 12:47
  • @elzooilogico The colon : serves the same as the / or ( in an echo. The prompt in a set /p may have as much leading spaces as you like - they are ignored.
    – user6811411
    Commented Aug 16, 2017 at 13:14

1 Answer 1

1

I am not sure I fully understand what you are trying to do, but try this:

@echo off
SET /P USER_INSTALL=Installation Path : 
if "%USER_INSTALL%"=="" goto IP1
goto :IP2

:IP1
echo "------Default path------"
PAUSE
exit

:IP2
ECHO %USER_INSTALL%
FOR /F "usebackq" %%i IN (`hostname`) DO SET HOST=%%i
ECHO %HOST%
PAUSE
exit

This organizes the code a bit. I added pause commands so you can see what it is doing. When testing this, I am not getting an "echo is off" error. Please let me know if it works!

Not the answer you're looking for? Browse other questions tagged or ask your own question.