Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 401
Anu Avatar asked May 20 '15 05:05

Anu


1 Answers

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

like image 82
MichaelS Avatar answered Sep 30 '22 18:09

MichaelS