setlocal ENABLEDELAYEDEXPANSION ENABLEEXTENSIONS

You may see this code in a windows bat script. You may think this command enables command extensions and delayed variable expansion. But this command actually have 3 effects:

  • set variable modifications local to this script, i.e., the change to variable value disappears after the script ends. The variables revert to their original values. Without setlocal, the changes of variables preserves even after the bat script exits. You can get the modified value in the cmd that runs the script.
  • enable command extensions. What is command extensions? Well, command extensions are those switches of commands that cannot be used if command extensions is disabled. For example, the For command can have a /L switch which generates a list of numbers for the loop variable. If the command extensions is not enabled, you will get this error when running this command:/L was unexpected at this time.

    Fortunately, command extensions is enabled by default. So theoretically, you do not need to enable it using setlocal  ENABLEEXTENSIONS. Most bat scripts do use “setlocal  ENABLEEXTENSIONS” to enable command extensions explicitly to make it clear and absolute. If you want to disable command extensions, you need to setlocal DISABLEEXTENSIONS. Note that if you use “setlocal DISABLEEXTENSIONS” in a script, the cmd process that runs the script is also affected, i.e., you cannot use command extensions in the cmd after the script executed. You can open a cmd window that disables command extensions by running “cmd /y“. Then FOR /L does not work in the cmd window, and in the scripts executed by that cmd.

  • Enable delayed expansion of variable.
Did you like this?
Tip admin with Cryptocurrency

Donate Bitcoin to admin

Scan to Donate Bitcoin to admin
Scan the QR code or copy the address below into your wallet to send some bitcoin:

Donate Bitcoin Cash to admin

Scan to Donate Bitcoin Cash to admin
Scan the QR code or copy the address below into your wallet to send bitcoin:

Donate Ethereum to admin

Scan to Donate Ethereum to admin
Scan the QR code or copy the address below into your wallet to send some Ether:

Donate Litecoin to admin

Scan to Donate Litecoin to admin
Scan the QR code or copy the address below into your wallet to send some Litecoin:

Donate Monero to admin

Scan to Donate Monero to admin
Scan the QR code or copy the address below into your wallet to send some Monero:

Donate ZCash to admin

Scan to Donate ZCash to admin
Scan the QR code or copy the address below into your wallet to send some ZCash:
Posted in

Leave a Reply