undefined environmental variable expansion in cmd

2019-07-19 18:41发布

问题:

On Windows command prompt:

D:\> echo %undef%
%undef%

D:\> type undef.bat
echo %undef%
D:\> undef

D:\> echo
ECHO is on.

My question is why on command line undefined environment variables like %undef% are expanded to %undef% but in BAT files are expanded to empty string?