Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

default value of Set /p in batch script

Is there a way to present a default value in a set /p statement in a Windows batch script?

For example, something like this:

set /p MyVar=My Default Value
echo $MyVar$

If the user presses Enter without typing anything else, then `MyVar gets that default value.

Thanks.

like image 916
Conrad S. Avatar asked Feb 07 '18 02:02

Conrad S.


1 Answers

The solutions proposed above did not work for me or they worked in a very clunky way.

This is (an obvious) simple solution to the problem I applied:

SET Docdir=D:\Documents\
SET /p Docdir="Target directory (Press Enter to keep <%Docdir%>): "

It results in the following prompt:

Target directory (Press Enter to use <D:\Documents\>):

User then see what's the default value and can accept it with Enter key

like image 63
Oak_3260548 Avatar answered Sep 20 '22 08:09

Oak_3260548