Anu
Anu

Reputation: 176

User input in batch file with default value

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.

Upvotes: 6

Views: 7338

Answers (1)

MichaelS
MichaelS

Reputation: 6042

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%.

Upvotes: 7

Related Questions