Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to clear a variable which is set from command line by "set /p var1="

Tags:

In Windows batch files, I accept variable from user input by set /p var1=, after var1 is used, I don't know how to reset/clear its value.

If I don't reset/clear its value, when user meets set /p var1= again, and user enter directly. the previous input value will be still there. I don't want it, How to reset it for new user input?

like image 604
Henry Leu Avatar asked Jun 14 '13 10:06

Henry Leu


People also ask

How do you clear a variable in CMD?

However, you can clear the value of an environment variable using Command Prompt. To unset an environment variable from Command Prompt, type the command setx variable_name “”.

What is set P in CMD?

set /p allows to have the user enter a value and assign it to a environment variable. The new line that echo writes can be piped into set /p to echo text without new lines.

How do you use SET P command?

The /P switch allows you to set the value of a variable to a line of input entered by the user. Displays the specified promptString before reading the line of input. The promptString can be empty. When batch file reaches this point (when left blank) it will halt and wait for user input.

What does set do in command line?

The set command is often used in the Autoexec. nt file to set environment variables. If you use the set command without any parameters, the current environment settings are displayed. These settings usually include the COMSPEC and PATH environment variables, which are used to help find programs on disk.


1 Answers

To clear a variable, regardless how it was set:

set "var1=" 
like image 158
dbenham Avatar answered Oct 11 '22 06:10

dbenham