USER
USER

Reputation: 23

What does "set _" in a for loop?

I had a problem that Win7 hangs on shutdown screen for over 30 mins..... then I found this batch file was the cause, but i dont understand what's the purpose of this.

The shutdown only hangs on after join to domain. This batch file was in c:\ntfs\bin After I removed this batch file, no more hangs

Issue fixed but i want to know what does this script mean. I dont know much about batch file please give me a hint


@echo off
for /f "usebackq tokens=1-2 delims==" %%a in (`set _`) do set %%a=

Upvotes: 0

Views: 450

Answers (2)

Stephan
Stephan

Reputation: 56180

It deletes all variables that start with an underscore (for example _test or _whatever)

Upvotes: 0

Endoro
Endoro

Reputation: 37569

use better:

for /f "delims==" %%a in ('set "_"') do set "%%a="

This code deletes all environment variables starting with _ (underscore) in the current setlocal-endlocal block. If you use this in a batch file without the setlocal command, the varialbles are removed from the current command prompt session.

The use of usebackq and tokens is not needed in this case, see help for for more help on the command prompt.

Upvotes: 2

Related Questions