6

I'm trying to prompt user for input in the batch file with default value (in case user doesn't enter input).

I am trying as given below: default values required: 1 to head.

set rev1=1
set rev2=HEAD
set /p rev1="start rev: default is %rev1% "
set /p rev2="end rev: default is %rev2% "

However prompt shows start rev: default is instead of start rev: default is 1.

Please help.

MC ND
  • 69,615
  • 8
  • 84
  • 126
Anu
  • 176
  • 1
  • 3
  • 14
  • 3
    If the posted code is placed between parenthesis (`if`, `for`, ...) then maybe [this answer](http://stackoverflow.com/a/30177832/2861476) could help. – MC ND May 20 '15 at 05:57
  • And put the first double quote left to `rev1` and `rev2` and not after equal sign. This is a common mistake explained hundreds of times in Stack Overflow batch file related topics. – Mofi May 20 '15 at 07:47

1 Answers1

7

I've tried c&p your code into a bat file and the output is start rev: default is 1. I guess you've posted just a snippet of your code and the this part is inside an IF or a FOR block. In this case you should add SETLOCAL EnableDelayedExpansion at the beginning of your script and access rev1 and rev2 with !rev1! and !rev2! instead of %rev1% and %rev2%.

MichaelS
  • 5,941
  • 6
  • 31
  • 46