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%)
Mishi
  • 628
  • 4
  • 16
  • 40
  • 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(`. – elzooilogico Aug 16 '17 at 12:42
  • 2
    Possible duplicate of [Windows Batch Variables Won't Set](https://stackoverflow.com/questions/9681863/windows-batch-variables-wont-set) – SomethingDark Aug 16 '17 at 12:46
  • 1
    Also, it's batch, not bash – SomethingDark Aug 16 '17 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. –  Aug 16 '17 at 13:14

1 Answers1

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!

J. Bond
  • 466
  • 4
  • 7